Created
July 18, 2024 10:00
-
-
Save mdjastrzebski/f9b7c0a73285020dfafb1c07726839ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Flutter | |
import React | |
import UIKit | |
/** | |
* Factory used by Flutter to create instances of FLReactView. | |
* @see https://docs.flutter.dev/platform-integration/ios/platform-views | |
*/ | |
class FLReactViewFactory: NSObject, FlutterPlatformViewFactory { | |
private var messenger: FlutterBinaryMessenger | |
init(messenger: FlutterBinaryMessenger) { | |
self.messenger = messenger | |
super.init() | |
} | |
func create( | |
withFrame frame: CGRect, | |
viewIdentifier viewId: Int64, | |
arguments args: Any? | |
) -> FlutterPlatformView { | |
let creationParams = args as? [String: Any] | |
return FLReactView( | |
frame: frame, | |
viewIdentifier: viewId, | |
arguments: creationParams, | |
binaryMessenger: messenger) | |
} | |
public func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol { | |
return FlutterStandardMessageCodec.sharedInstance() | |
} | |
} | |
/** | |
* Flutter platform view hosting React root view. | |
*/ | |
class FLReactView: NSObject, FlutterPlatformView { | |
private var reactRootView: RCTRootView | |
init( | |
frame: CGRect, | |
viewIdentifier viewId: Int64, | |
arguments args: [String: Any]?, | |
binaryMessenger messenger: FlutterBinaryMessenger? | |
) { | |
let jsCodeLocation = URL(string: "http://localhost:8081/index.bundle?platform=ios")! | |
reactRootView = RCTRootView( | |
bundleURL: jsCodeLocation, | |
moduleName: args!["moduleName"] as! String, | |
initialProperties: [:] as [NSObject : AnyObject], | |
launchOptions: nil | |
) | |
super.init() | |
} | |
func view() -> UIView { | |
return reactRootView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment