RubyMotion+ReactNative Notes
RubyMotion ReactNative 整合
Steps:
- Create rubymotion project
- Add motion-cocoapods
- Create ReactNative project
- Add ReactNative pods to rubymotion project
- Add ReactNative screen
motion create App
cd App
cat >> Gemfile <<EOF
gem 'motion-cocoapods'
EOF
yarn init
yarn add @react-native-community/cli
yarn react-native init reactnative --template react-native-template-typescript
cat >> Rakefile <<EOF
Motion::Project::App.setup do |app|
require_relative 'reactnative/node_modules/react-native/scripts/react_native_pods'
require_relative 'reactnative/node_modules/@react-native-community/cli-platform-ios/native_modules'
app.pods {
use_react_native!(path: 'reactnative/node_modules/react-native')
}
end
namespace :reactnative do
task 'dist' do
sh 'yarn --cwd reactnative dist'
end
end
EOF
# add into "scripts" part to reactnative/package.json
# "dev": "yarn react-native start",
# "dist": "yarn dist:jsbundle",
# "dist:jsbundle": "yarn react-native bundle --entry-file index.js --dev false --bundle-output ../resources/main.jsbundle",
### brew install moreutils jq
jq '.scripts *= {"dev": "yarn react-native start", "dist": "yarn dist:jsbundle", "dist:jsbundle": "yarn react-native bundle --entry-file index.js --dev false --bundle-output ../resources/main.jsbundle"}' package.json | sponge package.json
rake reactnative:dist
cat >> Rakefile <<EOF
namespace :sim do
task :se do
system("rake simulator device_name='iPhone SE (2nd generation)'")
end
task :eight do
system("rake simulator device_name='iPhone 8'")
end
task :plus do
system("rake simulator device_name='iPhone 8 Plus'")
end
task :ipad do
system("rake simulator device_name='iPad Pro (9.7-inch)'")
end
task :ipadpro do
system("rake simulator device_name='iPad Pro (12.9-inch) (4th generation)'")
end
end
EOF
cat > app/app_delegate.rb <<EOF
class AppDelegate
attr_accessor :window
def application(application, didFinishLaunchingWithOptions:launchOptions)
bridge = RCTBridge.alloc.initWithDelegate(self, launchOptions:launchOptions)
rootView = RCTRootView.alloc.initWithBridge(bridge, moduleName:"reactnative", initialProperties:nil)
rootView.backgroundColor = UIColor.alloc.initWithRed(1.0, green:1.0, blue:1.0, alpha:1)
self.window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
rootViewController = UIViewController.new
rootViewController.view = rootView
self.window.rootViewController = rootViewController
self.window.makeKeyAndVisible
return true
end
def sourceURLForBridge(bridge)
NSBundle.mainBundle.URLForResource("main", withExtension:"jsbundle")
end
end
EOF