1
0
mirror of https://github.com/flutter/samples.git synced 2026-04-28 02:18:47 +00:00

Add platform_view_swift based on platform_view example (#10)

This commit is contained in:
Mike Laughton
2018-08-10 16:39:22 -05:00
committed by Andrew Brogdon
parent 370a72caa5
commit c02d0208fa
34 changed files with 1230 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// Copyright 2018, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PlatformViewControllerDelegate
{
var flutterResult: FlutterResult?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel.init(name: "samples.flutter.io/platform_view_swift", binaryMessenger: controller)
channel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if ("switchView" == call.method) {
self.flutterResult = result
let platformViewController = controller.storyboard?.instantiateViewController(withIdentifier: "PlatformView") as! PlatformViewController
platformViewController.counter = call.arguments as! Int
platformViewController.delegate = self
let navigationController = UINavigationController(rootViewController: platformViewController)
navigationController.navigationBar.topItem?.title = "Platform View"
controller.present(navigationController, animated: true, completion: nil)
} else {
result(FlutterMethodNotImplemented)
}
});
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didUpdateCounter(counter: Int) {
flutterResult?(counter)
}
}