-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b585ae7
commit 87c468a
Showing
19 changed files
with
209 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// MyReactViewController.swift | ||
// chuckNorrisViewer2 | ||
// | ||
// Created by Tomoaki Imai on 2017/12/18. | ||
// Copyright © 2017 Tomoaki Imai. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import React | ||
|
||
class MyReactViewController : UIViewController { | ||
let reactTag = 100 | ||
var reactScene: ReactScene? | ||
let reactService: ReactService = ReactService() | ||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
guard let scene = reactScene else { | ||
return | ||
} | ||
let jsCodeLocation = URL(string: "http:https://localhost:8081/index.bundle?platform=ios") | ||
let reactView: UIView | ||
reactView = RCTRootView( | ||
bundleURL: jsCodeLocation, | ||
moduleName: "ChuckNorrisViewer", | ||
initialProperties: makeProperties(for: scene), | ||
launchOptions: nil | ||
) | ||
reactView.tag = reactTag | ||
reactView.frame = view.bounds | ||
reactView.translatesAutoresizingMaskIntoConstraints = true | ||
reactView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
view.addSubview(reactView) | ||
let callBack = {(event:ReactEvent) -> Void in | ||
switch(event) { | ||
case .nativeBack: | ||
self.removeView() | ||
} | ||
} | ||
|
||
reactService.setListener(callback: callBack) | ||
} | ||
|
||
private func removeView() { | ||
guard let v = view.viewWithTag(reactTag) else { | ||
return | ||
} | ||
v.removeFromSuperview() | ||
} | ||
|
||
private func makeProperties(for scene: ReactScene) -> [AnyHashable: Any] { | ||
var data: [AnyHashable: Any] = [:] | ||
scene.data.forEach { data[$0.key] = $0.value } | ||
let properties: [AnyHashable: Any] = [ | ||
"initialScene": scene.name, | ||
"data": data, | ||
] | ||
return properties | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// ReactEvent.swift | ||
// chuckNorrisViewer2 | ||
// | ||
// Created by Tomoaki Imai on 2018/01/08. | ||
// Copyright © 2018 Tomoaki Imai. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ReactEvent { | ||
case nativeBack | ||
|
||
init?(name: String, data: [String:Any]?) { | ||
switch (name, data) { | ||
case ("nativeBack", _): | ||
self = .nativeBack | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ReactScene.swift | ||
// chuckNorrisViewer2 | ||
// | ||
// Created by Tomoaki Imai on 2018/01/07. | ||
// Copyright © 2018 Tomoaki Imai. All rights reserved. | ||
// | ||
|
||
|
||
struct ReactScene { | ||
let name: String | ||
let data: [String: Any] | ||
|
||
init(name: String, data: [String: Any] = [:]) { | ||
self.name = name | ||
self.data = data | ||
} | ||
|
||
static func makeSearch() -> ReactScene { | ||
return ReactScene(name: .search) | ||
} | ||
|
||
} | ||
|
||
extension ReactScene { | ||
fileprivate typealias Scene = String | ||
} | ||
|
||
extension ReactScene.Scene { | ||
fileprivate static let search = "Search" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ReactService.swift | ||
// chuckNorrisViewer2 | ||
// | ||
// Created by Tomoaki Imai on 2018/01/08. | ||
// Copyright © 2018 Tomoaki Imai. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ReactEventCallback { | ||
|
||
let callback:((ReactEvent) -> Void) | ||
|
||
init(callback: @escaping ((ReactEvent) -> Void)) { | ||
self.callback = callback | ||
} | ||
func onEventCalled(reactEvent: ReactEvent) { | ||
callback(reactEvent) | ||
} | ||
} | ||
|
||
@objc final class ReactService: NSObject { | ||
@objc static let shared = ReactService() | ||
var reactEventCallback: ReactEventCallback? = nil | ||
|
||
@objc func handleEvent(_ name: String, data: [String: Any]?) { | ||
guard let event = ReactEvent(name: name, data: data) else { | ||
return | ||
} | ||
|
||
reactEventCallback?.onEventCalled(reactEvent: event) | ||
|
||
} | ||
|
||
func setListener(callback:@escaping (ReactEvent) -> Void) { | ||
print("listener set ") | ||
self.reactEventCallback = ReactEventCallback(callback: callback) | ||
} | ||
} |
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
File renamed without changes.
29 changes: 0 additions & 29 deletions
29
ios2/chuckNorrisViewer2/chuckNorrisViewer2/MyReactViewController.swift
This file was deleted.
Oops, something went wrong.