Last active
February 26, 2016 00:50
-
-
Save jaredly/74369ff3308db3bfa677 to your computer and use it in GitHub Desktop.
This file contains 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
export type Video = { | |
contentID: string, | |
duration: number, | |
} | |
type Props = { | |
video: Video, | |
onShowNext: () => void, | |
onError: (message: string) => void, | |
}; |
This file contains 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
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} | |
/> | |
} | |
} |
This file contains 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
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") | |
} | |
} |
This file contains 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
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