├── RNApp ├── .watchmanconfig ├── android │ ├── settings.gradle │ ├── app │ │ ├── src │ │ │ └── main │ │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ └── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── rnapp │ │ │ │ └── MainActivity.java │ │ ├── proguard-rules.pro │ │ ├── react.gradle │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── app │ ├── process.js │ ├── button.js │ └── index.js ├── index.ios.js ├── index.android.js ├── package.json ├── .gitignore ├── ios │ ├── RNApp │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── AppDelegate.m │ │ └── Base.lproj │ │ │ └── LaunchScreen.xib │ ├── RNAppTests │ │ ├── Info.plist │ │ └── RNAppTests.m │ └── RNApp.xcodeproj │ │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── RNApp.xcscheme │ │ └── project.pbxproj └── .flowconfig ├── meteor-app ├── .meteor │ ├── .gitignore │ ├── release │ ├── platforms │ ├── .id │ ├── .finished-upgraders │ ├── packages │ └── versions ├── client │ ├── index.html │ ├── home.html │ └── home.js ├── server │ └── app.js └── lib │ └── posts.js └── README.md /RNApp/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /meteor-app/.meteor/.gitignore: -------------------------------------------------------------------------------- 1 | local 2 | -------------------------------------------------------------------------------- /meteor-app/.meteor/release: -------------------------------------------------------------------------------- 1 | METEOR@1.2.1 2 | -------------------------------------------------------------------------------- /meteor-app/.meteor/platforms: -------------------------------------------------------------------------------- 1 | server 2 | browser 3 | -------------------------------------------------------------------------------- /RNApp/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'RNApp' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RNApp 3 | 4 | -------------------------------------------------------------------------------- /meteor-app/client/index.html: -------------------------------------------------------------------------------- 1 | 2 | meteor-app 3 | 4 | 5 | 6 | {{> home}} 7 | -------------------------------------------------------------------------------- /RNApp/app/process.js: -------------------------------------------------------------------------------- 1 | if (typeof process === 'undefined') process = {}; 2 | process.nextTick = setImmediate; 3 | 4 | module.exports = process; -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loongmxbt/meteor-react-native-basic/HEAD/RNApp/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loongmxbt/meteor-react-native-basic/HEAD/RNApp/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loongmxbt/meteor-react-native-basic/HEAD/RNApp/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loongmxbt/meteor-react-native-basic/HEAD/RNApp/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /meteor-app/client/home.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /RNApp/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RNApp/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 6 | -------------------------------------------------------------------------------- /RNApp/index.ios.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | AppRegistry, 3 | Component 4 | } from 'react-native'; 5 | 6 | import App from './app'; 7 | 8 | class RNApp extends Component { 9 | render() { 10 | return ; 11 | } 12 | } 13 | AppRegistry.registerComponent('RNApp', () => RNApp); -------------------------------------------------------------------------------- /RNApp/index.android.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | AppRegistry, 3 | Component 4 | } from 'react-native'; 5 | 6 | import App from './app'; 7 | 8 | class RNApp extends Component { 9 | render() { 10 | return ; 11 | } 12 | } 13 | AppRegistry.registerComponent('RNApp', () => RNApp); -------------------------------------------------------------------------------- /meteor-app/server/app.js: -------------------------------------------------------------------------------- 1 | Meteor.startup(function() { 2 | Posts.remove({}); 3 | if (Posts.find().count() === 0) { 4 | for (var i = 1; i <= 5; i++) { 5 | Posts.insert({title: "Post " + i}) 6 | }; 7 | } 8 | }); 9 | 10 | Meteor.publish('posts', function() { 11 | return Posts.find(); 12 | }); -------------------------------------------------------------------------------- /RNApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RNApp", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start" 7 | }, 8 | "dependencies": { 9 | "ddp": "^0.11.0", 10 | "ddp-client": "^0.1.2", 11 | "react-native": "^0.20.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /meteor-app/lib/posts.js: -------------------------------------------------------------------------------- 1 | Posts = new Mongo.Collection('posts'); 2 | 3 | Meteor.methods({ 4 | 'addPost': function() { 5 | Posts.insert({title: 'Post ' + Random.id()}); 6 | }, 7 | 8 | 'deletePost': function() { 9 | let post = Posts.findOne(); 10 | if (post) { 11 | Posts.remove({_id: post._id}); 12 | } 13 | } 14 | }) -------------------------------------------------------------------------------- /meteor-app/.meteor/.id: -------------------------------------------------------------------------------- 1 | # This file contains a token that is unique to your project. 2 | # Check it into your repository along with the rest of this directory. 3 | # It can be used for purposes such as: 4 | # - ensuring you don't accidentally deploy one app on top of another 5 | # - providing package authors with aggregated statistics 6 | 7 | t5vcazre15i1n35zqf 8 | -------------------------------------------------------------------------------- /meteor-app/.meteor/.finished-upgraders: -------------------------------------------------------------------------------- 1 | # This file contains information which helps Meteor properly upgrade your 2 | # app when you run 'meteor update'. You should check it into version control 3 | # with your project. 4 | 5 | notices-for-0.9.0 6 | notices-for-0.9.1 7 | 0.9.4-platform-file 8 | notices-for-facebook-graph-api-2 9 | 1.2.0-standard-minifiers-package 10 | 1.2.0-meteor-platform-split 11 | 1.2.0-cordova-changes 12 | 1.2.0-breaking-changes 13 | -------------------------------------------------------------------------------- /meteor-app/client/home.js: -------------------------------------------------------------------------------- 1 | Template.home.onCreated(function() { 2 | this.subscribe('posts'); 3 | }); 4 | 5 | Template.home.helpers({ 6 | count() { 7 | return Posts.find().count(); 8 | } 9 | }); 10 | 11 | Template.home.events({ 12 | 'click #increment': function(e) { 13 | e.preventDefault(); 14 | 15 | Meteor.call('addPost'); 16 | }, 17 | 18 | 'click #decrement': function(e) { 19 | e.preventDefault(); 20 | 21 | Meteor.call('deletePost'); 22 | } 23 | }) -------------------------------------------------------------------------------- /RNApp/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IJ 26 | # 27 | .idea 28 | .gradle 29 | local.properties 30 | 31 | # node.js 32 | # 33 | node_modules/ 34 | npm-debug.log 35 | -------------------------------------------------------------------------------- /RNApp/ios/RNApp/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /RNApp/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /RNApp/ios/RNApp/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RNApp/app/button.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | View, 3 | Text, 4 | TouchableOpacity, 5 | StyleSheet 6 | } from 'react-native'; 7 | 8 | export default React.createClass({ 9 | render() { 10 | let { text, onPress } = this.props; 11 | 12 | return ( 13 | 14 | {text} 15 | 16 | ); 17 | } 18 | }); 19 | 20 | const styles = StyleSheet.create({ 21 | button: { 22 | flex: 1, 23 | backgroundColor: '#eee', 24 | paddingHorizontal: 20, 25 | paddingVertical: 10, 26 | marginVertical: 10 27 | } 28 | }); -------------------------------------------------------------------------------- /RNApp/ios/RNApp/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Meteor React Native 示例应用 2 | 3 | ## 说明 4 | 实现了React Native -> Meteor 的 Posts 实时同步计数 5 | 6 | 原文来自:[Differential Blog](http://blog.differential.com/easily-connect-react-native-to-a-meteor-server/),修改了一系列bug。 7 | 8 | 中文版:[Meteor开发指南 — 连接React Native到Meteor Server](http://www.jianshu.com/p/2af9b6a5523b) 9 | 10 | ## 常见问题 11 | 12 | 1. babel 13 | rm node_modules/react-deep-force-update/.babelrc 14 | 15 | 2. process.nextTick is not a function 16 | http://stackoverflow.com/questions/34845760/process-nexttick-is-not-a-function-react-native-ddp-meteor 17 | https://github.com/spencercarli/meteor-todos-react-native/blob/master/ReactNativeTodos/app/config/db/lib/process.polyfill.js 18 | 19 | 3. 操作 Meteor App,React Native App 没有实时更新 20 | 可能与node-ddp包的observe有关,如何与React的组件生命周期联合使用,从而达到双向实时绑定呢? 21 | 22 | 4. Render()中使用let的话会有作用域问题,导致{count}不显示,需要使用var -------------------------------------------------------------------------------- /RNApp/ios/RNAppTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /RNApp/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /RNApp/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /meteor-app/.meteor/packages: -------------------------------------------------------------------------------- 1 | # Meteor packages used by this project, one per line. 2 | # Check this file (and the other files in this directory) into your repository. 3 | # 4 | # 'meteor add' and 'meteor remove' will edit this file for you, 5 | # but you can also edit it by hand. 6 | 7 | meteor-base # Packages every Meteor app needs to have 8 | mobile-experience # Packages for a great mobile UX 9 | mongo # The database Meteor supports right now 10 | blaze-html-templates # Compile .html files into Meteor Blaze views 11 | session # Client-side reactive dictionary for your app 12 | jquery # Helpful client-side library 13 | tracker # Meteor's client-side reactive programming library 14 | 15 | standard-minifiers # JS/CSS minifiers run for production mode 16 | es5-shim # ECMAScript 5 compatibility for older browsers. 17 | ecmascript # Enable ECMAScript2015+ syntax in app code 18 | 19 | random 20 | -------------------------------------------------------------------------------- /RNApp/android/app/src/main/java/com/rnapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rnapp; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.shell.MainReactPackage; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class MainActivity extends ReactActivity { 11 | 12 | /** 13 | * Returns the name of the main component registered from JavaScript. 14 | * This is used to schedule rendering of the component. 15 | */ 16 | @Override 17 | protected String getMainComponentName() { 18 | return "RNApp"; 19 | } 20 | 21 | /** 22 | * Returns whether dev mode should be enabled. 23 | * This enables e.g. the dev menu. 24 | */ 25 | @Override 26 | protected boolean getUseDeveloperSupport() { 27 | return BuildConfig.DEBUG; 28 | } 29 | 30 | /** 31 | * A list of packages used by the app. If the app uses additional views 32 | * or modules besides the default ones, add more packages here. 33 | */ 34 | @Override 35 | protected List getPackages() { 36 | return Arrays.asList( 37 | new MainReactPackage() 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /meteor-app/.meteor/versions: -------------------------------------------------------------------------------- 1 | autoupdate@1.2.4 2 | babel-compiler@5.8.24_1 3 | babel-runtime@0.1.4 4 | base64@1.0.4 5 | binary-heap@1.0.4 6 | blaze@2.1.3 7 | blaze-html-templates@1.0.1 8 | blaze-tools@1.0.4 9 | boilerplate-generator@1.0.4 10 | caching-compiler@1.0.0 11 | caching-html-compiler@1.0.2 12 | callback-hook@1.0.4 13 | check@1.1.0 14 | ddp@1.2.2 15 | ddp-client@1.2.1 16 | ddp-common@1.2.2 17 | ddp-server@1.2.2 18 | deps@1.0.9 19 | diff-sequence@1.0.1 20 | ecmascript@0.1.6 21 | ecmascript-runtime@0.2.6 22 | ejson@1.0.7 23 | es5-shim@4.1.14 24 | fastclick@1.0.7 25 | geojson-utils@1.0.4 26 | hot-code-push@1.0.0 27 | html-tools@1.0.5 28 | htmljs@1.0.5 29 | http@1.1.1 30 | id-map@1.0.4 31 | jquery@1.11.4 32 | launch-screen@1.0.4 33 | livedata@1.0.15 34 | logging@1.0.8 35 | meteor@1.1.10 36 | meteor-base@1.0.1 37 | minifiers@1.1.7 38 | minimongo@1.0.10 39 | mobile-experience@1.0.1 40 | mobile-status-bar@1.0.6 41 | mongo@1.1.3 42 | mongo-id@1.0.1 43 | npm-mongo@1.4.39_1 44 | observe-sequence@1.0.7 45 | ordered-dict@1.0.4 46 | promise@0.5.1 47 | random@1.0.5 48 | reactive-dict@1.1.3 49 | reactive-var@1.0.6 50 | reload@1.1.4 51 | retry@1.0.4 52 | routepolicy@1.0.6 53 | session@1.1.1 54 | spacebars@1.0.7 55 | spacebars-compiler@1.0.7 56 | standard-minifiers@1.0.2 57 | templating@1.1.5 58 | templating-tools@1.0.0 59 | tracker@1.0.9 60 | ui@1.0.8 61 | underscore@1.0.4 62 | url@1.0.5 63 | webapp@1.2.3 64 | webapp-hashing@1.0.5 65 | -------------------------------------------------------------------------------- /RNApp/ios/RNApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSAllowsArbitraryLoads 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /RNApp/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.web.js 5 | .*/*.android.js 6 | 7 | # Some modules have their own node_modules with overlap 8 | .*/node_modules/node-haste/.* 9 | 10 | # Ugh 11 | .*/node_modules/babel.* 12 | .*/node_modules/babylon.* 13 | .*/node_modules/invariant.* 14 | 15 | # Ignore react and fbjs where there are overlaps, but don't ignore 16 | # anything that react-native relies on 17 | .*/node_modules/fbjs/lib/Map.js 18 | .*/node_modules/fbjs/lib/Promise.js 19 | .*/node_modules/fbjs/lib/fetch.js 20 | .*/node_modules/fbjs/lib/ExecutionEnvironment.js 21 | .*/node_modules/fbjs/lib/isEmpty.js 22 | .*/node_modules/fbjs/lib/crc32.js 23 | .*/node_modules/fbjs/lib/ErrorUtils.js 24 | 25 | # Flow has a built-in definition for the 'react' module which we prefer to use 26 | # over the currently-untyped source 27 | .*/node_modules/react/react.js 28 | .*/node_modules/react/lib/React.js 29 | .*/node_modules/react/lib/ReactDOM.js 30 | 31 | # Ignore commoner tests 32 | .*/node_modules/commoner/test/.* 33 | 34 | # See https://github.com/facebook/flow/issues/442 35 | .*/react-tools/node_modules/commoner/lib/reader.js 36 | 37 | # Ignore jest 38 | .*/node_modules/jest-cli/.* 39 | 40 | # Ignore Website 41 | .*/website/.* 42 | 43 | [include] 44 | 45 | [libs] 46 | node_modules/react-native/Libraries/react-native/react-native-interface.js 47 | 48 | [options] 49 | module.system=haste 50 | 51 | munge_underscores=true 52 | 53 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 54 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\)$' -> 'RelativeImageStub' 55 | 56 | suppress_type=$FlowIssue 57 | suppress_type=$FlowFixMe 58 | suppress_type=$FixMe 59 | 60 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 61 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 62 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 63 | 64 | [version] 65 | 0.21.0 66 | -------------------------------------------------------------------------------- /RNApp/ios/RNApp/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCTRootView.h" 13 | 14 | @implementation AppDelegate 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | NSURL *jsCodeLocation; 19 | 20 | /** 21 | * Loading JavaScript code - uncomment the one you want. 22 | * 23 | * OPTION 1 24 | * Load from development server. Start the server from the repository root: 25 | * 26 | * $ npm start 27 | * 28 | * To run on device, change `localhost` to the IP address of your computer 29 | * (you can get this by typing `ifconfig` into the terminal and selecting the 30 | * `inet` value under `en0:`) and make sure your computer and iOS device are 31 | * on the same Wi-Fi network. 32 | */ 33 | 34 | jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; 35 | 36 | /** 37 | * OPTION 2 38 | * Load from pre-bundled file on disk. The static bundle is automatically 39 | * generated by "Bundle React Native code and images" build step. 40 | */ 41 | 42 | // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 43 | 44 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 45 | moduleName:@"RNApp" 46 | initialProperties:nil 47 | launchOptions:launchOptions]; 48 | 49 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 50 | UIViewController *rootViewController = [UIViewController new]; 51 | rootViewController.view = rootView; 52 | self.window.rootViewController = rootViewController; 53 | [self.window makeKeyAndVisible]; 54 | return YES; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /RNApp/ios/RNAppTests/RNAppTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import 12 | 13 | #import "RCTLog.h" 14 | #import "RCTRootView.h" 15 | 16 | #define TIMEOUT_SECONDS 240 17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 18 | 19 | @interface RNAppTests : XCTestCase 20 | 21 | @end 22 | 23 | @implementation RNAppTests 24 | 25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 26 | { 27 | if (test(view)) { 28 | return YES; 29 | } 30 | for (UIView *subview in [view subviews]) { 31 | if ([self findSubviewInView:subview matching:test]) { 32 | return YES; 33 | } 34 | } 35 | return NO; 36 | } 37 | 38 | - (void)testRendersWelcomeScreen 39 | { 40 | UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 42 | BOOL foundElement = NO; 43 | 44 | __block NSString *redboxError = nil; 45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 46 | if (level >= RCTLogLevelError) { 47 | redboxError = message; 48 | } 49 | }); 50 | 51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 57 | return YES; 58 | } 59 | return NO; 60 | }]; 61 | } 62 | 63 | RCTSetLogFunction(RCTDefaultLogFunction); 64 | 65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /RNApp/app/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import React, { 4 | View, 5 | Text, 6 | StyleSheet 7 | } from 'react-native'; 8 | 9 | import Button from './button'; 10 | 11 | import DDPClient from 'ddp-client'; 12 | let ddpClient = new DDPClient(); 13 | 14 | import process from './process'; 15 | 16 | export default React.createClass({ 17 | getInitialState() { 18 | return { 19 | connected: false, 20 | posts: {} 21 | } 22 | }, 23 | 24 | componentDidMount() { 25 | ddpClient.connect((err, wasReconnect) => { 26 | let connected = true; 27 | if (err) { 28 | connected = false; 29 | } else { 30 | this.makeSubscription(); 31 | this.observePosts(); 32 | } 33 | this.setState({ connected: connected }); 34 | }); 35 | }, 36 | 37 | makeSubscription() { 38 | ddpClient.subscribe("posts", [], () => { 39 | this.setState({posts: ddpClient.collections.posts}); 40 | }); 41 | }, 42 | 43 | observePosts() { 44 | let observer = ddpClient.observe("posts"); 45 | observer.added = (id) => { 46 | this.setState({posts: ddpClient.collections.posts}); 47 | } 48 | observer.changed = (id, oldFields, clearedFields, newFields) => { 49 | this.setState({posts: ddpClient.collections.posts}); 50 | } 51 | observer.removed = (id, oldValue) => { 52 | this.setState({posts: ddpClient.collections.posts}); 53 | } 54 | }, 55 | 56 | handleIncrement() { 57 | ddpClient.call('addPost', [], (err, result) => { 58 | console.log('called function, result: ' + result); 59 | }, () => { 60 | this.setState({posts: ddpClient.collections.posts}); 61 | }); 62 | }, 63 | 64 | handleDecrement() { 65 | ddpClient.call('deletePost', [], (err, result) => { 66 | console.log('called function, result: ' + result); 67 | }, () => { 68 | this.setState({posts: ddpClient.collections.posts}); 69 | }); 70 | }, 71 | 72 | render() { 73 | var items = this.state.posts.items || {}; 74 | var count = Object.keys(items).length; 75 | return ( 76 | 77 | 78 | Posts: {count} 79 |