Skip to content

Commit

Permalink
configure ios
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoima525 committed Jan 12, 2018
1 parent b585ae7 commit 87c468a
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DerivedData
*.xcuserstate
project.xcworkspace
ios/Pods
ios2/chuckNorrisViewer2/Pods
ios2/Pods
# Android/IntelliJ
#
build/
Expand Down
11 changes: 6 additions & 5 deletions ios2/chuckNorrisViewer2/Podfile → ios2/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ platform :ios, '9.0'
target 'chuckNorrisViewer2' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'React', :path => '../../node_modules/react-native', :subspecs => [
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTLinkingIOS',
'RCTAnimation',
'RCTImage',
'RCTText',
'RCTNetwork',
'RCTWebSocket', # needed for debugging
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod "yoga", :path => "../../node_modules/react-native/ReactCommon/yoga"
pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"

# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'GLog', :podspec => '../../node_modules/react-native/third-party-podspecs/GLog.podspec'
pod 'Folly', :podspec => '../../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'GLog', :podspec => '../node_modules/react-native/third-party-podspecs/GLog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
# Pods for chuckNorrisViewer2

end
36 changes: 18 additions & 18 deletions ios2/chuckNorrisViewer2/Podfile.lock → ios2/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ PODS:
- yoga (0.51.0.React)

DEPENDENCIES:
- DoubleConversion (from `../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- Folly (from `../../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- GLog (from `../../node_modules/react-native/third-party-podspecs/GLog.podspec`)
- React/Core (from `../../node_modules/react-native`)
- React/CxxBridge (from `../../node_modules/react-native`)
- React/DevSupport (from `../../node_modules/react-native`)
- React/RCTImage (from `../../node_modules/react-native`)
- React/RCTLinkingIOS (from `../../node_modules/react-native`)
- React/RCTNetwork (from `../../node_modules/react-native`)
- React/RCTText (from `../../node_modules/react-native`)
- React/RCTWebSocket (from `../../node_modules/react-native`)
- yoga (from `../../node_modules/react-native/ReactCommon/yoga`)
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- GLog (from `../node_modules/react-native/third-party-podspecs/GLog.podspec`)
- React/Core (from `../node_modules/react-native`)
- React/CxxBridge (from `../node_modules/react-native`)
- React/DevSupport (from `../node_modules/react-native`)
- React/RCTImage (from `../node_modules/react-native`)
- React/RCTLinkingIOS (from `../node_modules/react-native`)
- React/RCTNetwork (from `../node_modules/react-native`)
- React/RCTText (from `../node_modules/react-native`)
- React/RCTWebSocket (from `../node_modules/react-native`)
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)

EXTERNAL SOURCES:
DoubleConversion:
:podspec: "../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
Folly:
:podspec: "../../node_modules/react-native/third-party-podspecs/Folly.podspec"
:podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec"
GLog:
:podspec: "../../node_modules/react-native/third-party-podspecs/GLog.podspec"
:podspec: "../node_modules/react-native/third-party-podspecs/GLog.podspec"
React:
:path: "../../node_modules/react-native"
:path: "../node_modules/react-native"
yoga:
:path: "../../node_modules/react-native/ReactCommon/yoga"
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
boost: 30a15ffb6d9aa4646dd3caffc960753f4cb4ca4e
Expand All @@ -89,6 +89,6 @@ SPEC CHECKSUMS:
React: 352f02f1db6e4744f9a758527e13e3fdefbbd6ba
yoga: b5d96400ca8b2936965a7a6516da7c1177f432a3

PODFILE CHECKSUM: 644e41234f966ac3acffeb53fd730da100edd152
PODFILE CHECKSUM: b8a381067bd1c82dc6a11b5d0e4eb4b70ee639dd

COCOAPODS: 1.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
27130C5190832B04DA26E7AC /* Pods_chuckNorrisViewer2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A7FF68BDED18429844B326 /* Pods_chuckNorrisViewer2.framework */; };
F38C67D52003523F001BA762 /* ReactScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = F38C67D42003523F001BA762 /* ReactScene.swift */; };
F38C67D72003BB45001BA762 /* ReactService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F38C67D62003BB45001BA762 /* ReactService.swift */; };
F38C67D92003BBFE001BA762 /* ReactEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F38C67D82003BBFE001BA762 /* ReactEvent.swift */; };
F393C90F1FE83E7600EB0CC0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F393C90E1FE83E7600EB0CC0 /* AppDelegate.swift */; };
F393C9111FE83E7600EB0CC0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F393C9101FE83E7600EB0CC0 /* ViewController.swift */; };
F393C9141FE83E7600EB0CC0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F393C9121FE83E7600EB0CC0 /* Main.storyboard */; };
Expand All @@ -21,6 +24,9 @@
19A0D48AA1EF43965A659DA8 /* Pods-chuckNorrisViewer2.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-chuckNorrisViewer2.debug.xcconfig"; path = "Pods/Target Support Files/Pods-chuckNorrisViewer2/Pods-chuckNorrisViewer2.debug.xcconfig"; sourceTree = "<group>"; };
3E5A0526109D46744E967341 /* Pods-chuckNorrisViewer2.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-chuckNorrisViewer2.release.xcconfig"; path = "Pods/Target Support Files/Pods-chuckNorrisViewer2/Pods-chuckNorrisViewer2.release.xcconfig"; sourceTree = "<group>"; };
C6A7FF68BDED18429844B326 /* Pods_chuckNorrisViewer2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_chuckNorrisViewer2.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F38C67D42003523F001BA762 /* ReactScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactScene.swift; sourceTree = "<group>"; };
F38C67D62003BB45001BA762 /* ReactService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactService.swift; sourceTree = "<group>"; };
F38C67D82003BBFE001BA762 /* ReactEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactEvent.swift; sourceTree = "<group>"; };
F393C90B1FE83E7600EB0CC0 /* chuckNorrisViewer2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chuckNorrisViewer2.app; sourceTree = BUILT_PRODUCTS_DIR; };
F393C90E1FE83E7600EB0CC0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F393C9101FE83E7600EB0CC0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -63,6 +69,18 @@
name = Frameworks;
sourceTree = "<group>";
};
F38C67D320035217001BA762 /* ReactNative */ = {
isa = PBXGroup;
children = (
F393C9221FE8A30F00EB0CC0 /* ReactEventHook.h */,
F393C9241FE8A36100EB0CC0 /* ReactEventHook.m */,
F38C67D42003523F001BA762 /* ReactScene.swift */,
F38C67D62003BB45001BA762 /* ReactService.swift */,
F38C67D82003BBFE001BA762 /* ReactEvent.swift */,
);
path = ReactNative;
sourceTree = "<group>";
};
F393C9021FE83E7600EB0CC0 = {
isa = PBXGroup;
children = (
Expand All @@ -84,15 +102,14 @@
F393C90D1FE83E7600EB0CC0 /* chuckNorrisViewer2 */ = {
isa = PBXGroup;
children = (
F38C67D320035217001BA762 /* ReactNative */,
F393C90E1FE83E7600EB0CC0 /* AppDelegate.swift */,
F393C9101FE83E7600EB0CC0 /* ViewController.swift */,
F393C9121FE83E7600EB0CC0 /* Main.storyboard */,
F393C9151FE83E7600EB0CC0 /* Assets.xcassets */,
F393C9171FE83E7600EB0CC0 /* LaunchScreen.storyboard */,
F393C91A1FE83E7600EB0CC0 /* Info.plist */,
F393C9201FE8811E00EB0CC0 /* MyReactViewController.swift */,
F393C9221FE8A30F00EB0CC0 /* ReactEventHook.h */,
F393C9241FE8A36100EB0CC0 /* ReactEventHook.m */,
F393C9231FE8A36000EB0CC0 /* chuckNorrisViewer2-Bridging-Header.h */,
);
path = chuckNorrisViewer2;
Expand Down Expand Up @@ -222,9 +239,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F38C67D52003523F001BA762 /* ReactScene.swift in Sources */,
F393C9111FE83E7600EB0CC0 /* ViewController.swift in Sources */,
F393C9251FE8A36100EB0CC0 /* ReactEventHook.m in Sources */,
F38C67D72003BB45001BA762 /* ReactService.swift in Sources */,
F393C90F1FE83E7600EB0CC0 /* AppDelegate.swift in Sources */,
F38C67D92003BBFE001BA762 /* ReactEvent.swift in Sources */,
F393C9211FE8811E00EB0CC0 /* MyReactViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
File renamed without changes.
60 changes: 60 additions & 0 deletions ios2/chuckNorrisViewer2/MyReactViewController.swift
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
}
}
22 changes: 22 additions & 0 deletions ios2/chuckNorrisViewer2/ReactNative/ReactEvent.swift
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ReactEventHook.h"
#import <React/RCTLog.h>
#import "chuckNorrisViewer2-Swift.h"

@implementation ReactEventHook

Expand All @@ -16,5 +17,6 @@ @implementation ReactEventHook
RCT_EXPORT_METHOD(sendEvent:(NSString *)name data:(nullable NSDictionary *)data)
{
RCTLogInfo(@"Pretending to create an event %@ at %@", name, data);
[ReactService.shared handleEvent:name data:data];
}
@end
31 changes: 31 additions & 0 deletions ios2/chuckNorrisViewer2/ReactNative/ReactScene.swift
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"
}
40 changes: 40 additions & 0 deletions ios2/chuckNorrisViewer2/ReactNative/ReactService.swift
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ViewController: UIViewController {

@IBAction
func openReact(_ sender:UIButton) {
let nextView = storyboard!.instantiateViewController(withIdentifier: "ReactView")
let nextView = storyboard!.instantiateViewController(withIdentifier: "ReactView") as! MyReactViewController
nextView.reactScene = ReactScene.makeSearch()
self.present(nextView, animated: true, completion: nil)
}
}
Expand Down

This file was deleted.

0 comments on commit 87c468a

Please sign in to comment.