Skip to content

Instantly share code, notes, and snippets.

@jaredly
Last active February 26, 2016 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredly/74369ff3308db3bfa677 to your computer and use it in GitHub Desktop.
Save jaredly/74369ff3308db3bfa677 to your computer and use it in GitHub Desktop.
export type Video = {
contentID: string,
duration: number,
}
type Props = {
video: Video,
onShowNext: () => void,
onError: (message: string) => void,
};
class SignInWrapper extends React.Component {
render() {
return <SignIn
onError={(message: string) => {
let onError$message = message
ReactNativeCallbackManager.callNative(this.props.onError, {message: onError$message})
}}
onShowNext={() => {
ReactNativeCallbackManager.callNative(this.props.onShowNext, {})
}}
video={this.props.video}
/>
}
}
public class SignIn: ReactNativeComponent {
init(onError: (message: String) -> Void, onShowNext: () -> Void, video: SimpleVideo) {
var properties: [String: AnyObject] = [:]
var callbacks: [Int] = []
let registerCallback: (([String: AnyObject]) -> Void) -> Int = {fn in
let id = ReactNativeCallbackManager.registerCallback(fn)
callbacks.append(id)
return id
}
properties["onError"] = registerCallback({args$ in
let onError_message: String = args$["message"]! as! String
onError(message: onError_message)
})
properties["onShowNext"] = registerCallback({args$ in
onShowNext()
})
properties["video"] = {
let video_contentID: String = video.contentID
let video_duration: Int = video.duration
return ["contentID": video_contentID, "duration": video_duration]
}()
super.init(name: "SignIn", properties: properties, callbacks: callbacks)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
public class ReactNativeComponent: UIViewController {
let callbacks: [Int]
let properties: [String: AnyObject]
let name: String
init(name: String, properties: [String: AnyObject], callbacks: [Int]) {
self.name = name
self.properties = properties
self.callbacks = callbacks
super.init(nibName: nil, bundle: nil)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func loadView() {
view = ReactNativeBridge.sharedInstance.createRootComponentForModule(name, initialProperties: properties)
}
deinit {
ReactNativeCallbackManager.unregisterCallbacks(callbacks)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment