Skip to content

Instantly share code, notes, and snippets.

@jemise111
Last active January 7, 2016 21:48
Show Gist options
  • Save jemise111/ea16d6590f3a4e6ad9d0 to your computer and use it in GitHub Desktop.
Save jemise111/ea16d6590f3a4e6ad9d0 to your computer and use it in GitHub Desktop.
//
// ReactNativeViewSwift.swift
//
import UIKit
class ReactNativeViewSwift: UIView {
var data: [String: AnyObject]?
func initializeReactView() {
let REACT_DEV_MODE = false
if self.data == nil {
self.data = [String: AnyObject]()
}
// this is a good place to pass configuration variables
self.data!["DEV_MODE"] = REACT_DEV_MODE
self.data!["API_KEY"] = "ABCDEF123456"
self.data!["AUTHORIZATION_TOKEN"] = "a8b6de25b5bf481824c9c4173c56231a"
var jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")
if !REACT_DEV_MODE {
jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")
}
let rootView = RCTRootView(bundleURL: jsCodeLocation,
moduleName: "ReactNativeExample",
initialProperties: self.data!,
launchOptions: nil)
rootView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(rootView)
let views = ["rootView": rootView]
var constraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[rootView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
constraints += NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[rootView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
self.addConstraints(constraints)
self.layoutIfNeeded()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment