├── .babelrc ├── .buckconfig ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── README.md ├── __tests__ ├── index.android.js └── index.ios.js ├── android ├── app │ ├── BUCK │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ ├── MainActivity.java │ │ │ └── MainApplication.java │ │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── keystores │ ├── BUCK │ └── debug.keystore.properties └── settings.gradle ├── app ├── components │ ├── badge.js │ ├── navigation.js │ ├── separatorLine.js │ ├── settingView.js │ └── toast.js ├── images │ ├── more_icon@2x.png │ ├── more_icon@3x.png │ ├── tab_message_highlight_icon@2x.png │ ├── tab_message_highlight_icon@3x.png │ ├── tab_message_icon@2x.png │ └── tab_message_icon@3x.png └── layout │ ├── chatPage.js │ ├── conversationListPage.js │ ├── friendListPage.js │ ├── loginPage.js │ ├── mainPage.js │ ├── pretreatmentPage.js │ └── settingPage.js ├── assets ├── IMG_0100.PNG └── IMG_0101.PNG ├── index.android.js ├── index.ios.js ├── ios ├── Example.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ └── Example.xcscheme ├── Example │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ └── LaunchScreen.xib │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── main.m └── ExampleTests │ ├── ExampleTests.m │ └── Info.plist └── package.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } -------------------------------------------------------------------------------- /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*[.]android.js 5 | 6 | # Ignore templates with `@flow` in header 7 | .*/local-cli/generator.* 8 | 9 | # Ignore malformed json 10 | .*/node_modules/y18n/test/.*\.json 11 | 12 | # Ignore the website subdir 13 | /website/.* 14 | 15 | # Ignore BUCK generated dirs 16 | /\.buckd/ 17 | 18 | # Ignore unexpected extra @providesModule 19 | .*/node_modules/commoner/test/source/widget/share.js 20 | .*/node_modules/.*/node_modules/fbjs/.* 21 | 22 | # Ignore duplicate module providers 23 | # For RN Apps installed via npm, "Libraries" folder is inside node_modules/react-native but in the source repo it is in the root 24 | .*/Libraries/react-native/React.js 25 | .*/Libraries/react-native/ReactNative.js 26 | .*/node_modules/jest-runtime/build/__tests__/.* 27 | 28 | [include] 29 | 30 | [libs] 31 | node_modules/react-native/Libraries/react-native/react-native-interface.js 32 | node_modules/react-native/flow 33 | flow/ 34 | 35 | [options] 36 | module.system=haste 37 | 38 | esproposal.class_static_fields=enable 39 | esproposal.class_instance_fields=enable 40 | 41 | experimental.strict_type_args=true 42 | 43 | munge_underscores=true 44 | 45 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 46 | 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\|pdf\)$' -> 'RelativeImageStub' 47 | 48 | suppress_type=$FlowIssue 49 | suppress_type=$FlowFixMe 50 | suppress_type=$FixMe 51 | 52 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-3]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 53 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-3]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 54 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 55 | 56 | unsafe.enable_getters_and_setters=true 57 | 58 | [version] 59 | ^0.33.0 60 | -------------------------------------------------------------------------------- /.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 | *.iml 28 | .idea 29 | .gradle 30 | local.properties 31 | 32 | # node.js 33 | # 34 | node_modules/ 35 | npm-debug.log 36 | 37 | # BUCK 38 | buck-out/ 39 | \.buckd/ 40 | android/app/libs 41 | *.keystore 42 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #plugin 2 | [react-native-jmessage](https://github.com/xsdlr/react-native-jmessage) 3 | 4 | # run steps 5 | * install npm dependencies 6 | ``` 7 | npm install 8 | ``` 9 | * link react native plugin 10 | ``` 11 | react-native link 12 | ``` 13 | * make sure your application package name is right 14 | 15 | #preview 16 | ![image](https://github.com/xsdlr/react-native-jmessage-example/raw/master/assets/IMG_0100.PNG) 17 | ![image](https://github.com/xsdlr/react-native-jmessage-example/raw/master/assets/IMG_0101.PNG) 18 | 19 | 20 | -------------------------------------------------------------------------------- /__tests__/index.android.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.android.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /__tests__/index.ios.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.ios.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /android/app/BUCK: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # To learn about Buck see [Docs](https://buckbuild.com/). 4 | # To run your application with Buck: 5 | # - install Buck 6 | # - `npm start` - to start the packager 7 | # - `cd android` 8 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 9 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 10 | # - `buck install -r android/app` - compile, install and run application 11 | # 12 | 13 | lib_deps = [] 14 | for jarfile in glob(['libs/*.jar']): 15 | name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) 16 | lib_deps.append(':' + name) 17 | prebuilt_jar( 18 | name = name, 19 | binary_jar = jarfile, 20 | ) 21 | 22 | for aarfile in glob(['libs/*.aar']): 23 | name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) 24 | lib_deps.append(':' + name) 25 | android_prebuilt_aar( 26 | name = name, 27 | aar = aarfile, 28 | ) 29 | 30 | android_library( 31 | name = 'all-libs', 32 | exported_deps = lib_deps 33 | ) 34 | 35 | android_library( 36 | name = 'app-code', 37 | srcs = glob([ 38 | 'src/main/java/**/*.java', 39 | ]), 40 | deps = [ 41 | ':all-libs', 42 | ':build_config', 43 | ':res', 44 | ], 45 | ) 46 | 47 | android_build_config( 48 | name = 'build_config', 49 | package = 'com.example', 50 | ) 51 | 52 | android_resource( 53 | name = 'res', 54 | res = 'src/main/res', 55 | package = 'com.example', 56 | ) 57 | 58 | android_binary( 59 | name = 'app', 60 | package_type = 'debug', 61 | manifest = 'src/main/AndroidManifest.xml', 62 | keystore = '//android/keystores:debug', 63 | deps = [ 64 | ':app-code', 65 | ], 66 | ) 67 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // the root of your project, i.e. where "package.json" lives 37 | * root: "../../", 38 | * 39 | * // where to put the JS bundle asset in debug mode 40 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 41 | * 42 | * // where to put the JS bundle asset in release mode 43 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 44 | * 45 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 46 | * // require('./image.png')), in debug mode 47 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 48 | * 49 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 50 | * // require('./image.png')), in release mode 51 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 52 | * 53 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 54 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 55 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 56 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 57 | * // for example, you might want to remove it from here. 58 | * inputExcludes: ["android/**", "ios/**"], 59 | * 60 | * // override which node gets called and with what additional arguments 61 | * nodeExecutableAndArgs: ["node"] 62 | * 63 | * // supply additional arguments to the packager 64 | * extraPackagerArgs: [] 65 | * ] 66 | */ 67 | 68 | apply from: "../../node_modules/react-native/react.gradle" 69 | 70 | /** 71 | * Set this to true to create two separate APKs instead of one: 72 | * - An APK that only works on ARM devices 73 | * - An APK that only works on x86 devices 74 | * The advantage is the size of the APK is reduced by about 4MB. 75 | * Upload all the APKs to the Play Store and people will download 76 | * the correct one based on the CPU architecture of their device. 77 | */ 78 | def enableSeparateBuildPerCPUArchitecture = false 79 | 80 | /** 81 | * Run Proguard to shrink the Java bytecode in release builds. 82 | */ 83 | def enableProguardInReleaseBuilds = false 84 | 85 | android { 86 | compileSdkVersion 23 87 | buildToolsVersion "23.0.1" 88 | 89 | defaultConfig { 90 | applicationId "com.example" 91 | minSdkVersion 16 92 | targetSdkVersion 22 93 | versionCode 1 94 | versionName "1.0" 95 | ndk { 96 | abiFilters "armeabi-v7a", "x86" 97 | } 98 | } 99 | splits { 100 | abi { 101 | reset() 102 | enable enableSeparateBuildPerCPUArchitecture 103 | universalApk false // If true, also generate a universal APK 104 | include "armeabi-v7a", "x86" 105 | } 106 | } 107 | buildTypes { 108 | release { 109 | minifyEnabled enableProguardInReleaseBuilds 110 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 111 | } 112 | } 113 | // applicationVariants are e.g. debug, release 114 | applicationVariants.all { variant -> 115 | variant.outputs.each { output -> 116 | // For each separate APK per architecture, set a unique version code as described here: 117 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 118 | def versionCodes = ["armeabi-v7a":1, "x86":2] 119 | def abi = output.getFilter(OutputFile.ABI) 120 | if (abi != null) { // null for the universal-debug, universal-release variants 121 | output.versionCodeOverride = 122 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 123 | } 124 | } 125 | } 126 | } 127 | 128 | dependencies { 129 | compile fileTree(dir: "libs", include: ["*.jar"]) 130 | compile "com.android.support:appcompat-v7:23.0.1" 131 | compile "com.facebook.react:react-native:+" // From node_modules 132 | } 133 | 134 | // Run this once to be able to run the application with BUCK 135 | // puts all compile dependencies into folder libs for BUCK to use 136 | task copyDownloadableDepsToLibs(type: Copy) { 137 | from configurations.compile 138 | into 'libs' 139 | } 140 | -------------------------------------------------------------------------------- /android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # okhttp 54 | 55 | -keepattributes Signature 56 | -keepattributes *Annotation* 57 | -keep class okhttp3.** { *; } 58 | -keep interface okhttp3.** { *; } 59 | -dontwarn okhttp3.** 60 | 61 | # okio 62 | 63 | -keep class sun.misc.Unsafe { *; } 64 | -dontwarn java.nio.file.* 65 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 66 | -dontwarn okio.** 67 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "Example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | import android.util.Log; 5 | 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactInstanceManager; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactPackage; 10 | import com.facebook.react.shell.MainReactPackage; 11 | import com.facebook.soloader.SoLoader; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 19 | @Override 20 | protected boolean getUseDeveloperSupport() { 21 | return BuildConfig.DEBUG; 22 | } 23 | 24 | @Override 25 | protected List getPackages() { 26 | return Arrays.asList( 27 | new MainReactPackage() 28 | ); 29 | } 30 | }; 31 | 32 | @Override 33 | public ReactNativeHost getReactNativeHost() { 34 | return mReactNativeHost; 35 | } 36 | 37 | @Override 38 | public void onCreate() { 39 | super.onCreate(); 40 | SoLoader.init(this, /* native exopackage */ false); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = 'debug', 3 | store = 'debug.keystore', 4 | properties = 'debug.keystore.properties', 5 | visibility = [ 6 | 'PUBLIC', 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /app/components/badge.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/18. 3 | */ 4 | import React from 'react'; 5 | import { 6 | StyleSheet, 7 | Text, 8 | PixelRatio, 9 | } from 'react-native'; 10 | export default class Badge extends React.Component { 11 | static propTypes = Text.propTypes; 12 | render() { 13 | return ( 14 | 18 | {this.props.children} 19 | 20 | ); 21 | } 22 | } 23 | 24 | const styles = StyleSheet.create({ 25 | container: { 26 | fontSize: 12, 27 | color: 'white', 28 | backgroundColor: 'red', 29 | lineHeight: 16, 30 | height: 16, 31 | width: 16, 32 | textAlign: 'center', 33 | borderWidth: 1 + (1 / PixelRatio.get()), 34 | borderColor: 'red', 35 | borderRadius: 8, 36 | overflow: 'hidden', 37 | }, 38 | }); -------------------------------------------------------------------------------- /app/components/navigation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/10. 3 | */ 4 | import React, { 5 | Component, 6 | PropTypes, 7 | } from 'react'; 8 | import { 9 | Navigator, 10 | Platform, 11 | BackAndroid, 12 | } from 'react-native'; 13 | 14 | let _navigator; 15 | export default class Navigation extends Component { 16 | static propTypes = { 17 | initialRoute: PropTypes.object.isRequired, 18 | }; 19 | componentDidMount() { 20 | if (Platform.OS === 'android') { 21 | BackAndroid.addEventListener('hardwareBackPress', () => { 22 | const routesList = _navigator.getCurrentRoutes(); 23 | if (routesList.length > 1) { 24 | _navigator.pop(); 25 | return true; 26 | } 27 | return false; 28 | }); 29 | } 30 | } 31 | componentWillUnmount() { 32 | BackAndroid.removeEventListener('hardwareBackPress'); 33 | } 34 | configureScene(route) { 35 | if (route.sceneConfig) { 36 | return route.sceneConfig; 37 | } 38 | return Navigator.SceneConfigs.PushFromRight; 39 | } 40 | render() { 41 | return ( 42 | { 46 | _navigator = navigator; 47 | }} 48 | configureScene={this.configureScene.bind(this)} 49 | renderScene={(route, navigator) => { 50 | return ; 51 | }} 52 | /> 53 | ); 54 | } 55 | } -------------------------------------------------------------------------------- /app/components/separatorLine.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/10. 3 | */ 4 | import React, { 5 | Component, 6 | PropTypes, 7 | } from 'react'; 8 | import { 9 | StyleSheet, 10 | View, 11 | } from 'react-native'; 12 | 13 | export default class SeparatorLine extends Component { 14 | static propTypes = { 15 | spaceLeftWidth: PropTypes.number, 16 | spaceRightWidth: PropTypes.number, 17 | color: PropTypes.string, 18 | spaceColor: PropTypes.string, 19 | }; 20 | static defaultProps = { 21 | spaceLeftWidth: 0, 22 | spaceRightWidth: 0, 23 | color: '#E0E0E0', 24 | spaceColor: 'white', 25 | }; 26 | render() { 27 | return ( 28 | 29 | 30 | 31 | 32 | 33 | ); 34 | } 35 | } -------------------------------------------------------------------------------- /app/components/settingView.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/18. 3 | */ 4 | import React, { 5 | Component, 6 | PropTypes, 7 | } from 'react'; 8 | import { 9 | StyleSheet, 10 | View, 11 | Text, 12 | Image, 13 | TouchableWithoutFeedback, 14 | } from 'react-native'; 15 | 16 | export default class SettingView extends Component { 17 | static propTypes = { 18 | style: View.propTypes.style, 19 | src: Image.propTypes.source, 20 | text: PropTypes.string, 21 | textStyle: Text.propTypes.style, 22 | detailText: PropTypes.string, 23 | detailTextStyle: Text.propTypes.style, 24 | onPress: TouchableWithoutFeedback.propTypes.onPress, 25 | rightViewAlign: PropTypes.oneOf([ 'flex-start', 'flex-end', 'center', 'space-between', 'space-around' ]), 26 | rightView: PropTypes.func, 27 | isRightArrowShow: PropTypes.bool, 28 | }; 29 | static defaultProps = { 30 | isRightArrowShow: true, 31 | rightViewAlign: 'flex-end', 32 | }; 33 | _renderRightView() { 34 | const rightView = this.props.rightView(); 35 | return React.cloneElement(rightView, { 36 | style: rightView.props.style, 37 | }); 38 | } 39 | render() { 40 | return ( 41 | 42 | 43 | { 44 | this.props.src ? 45 | : null 49 | } 50 | { 51 | this.props.src ? 52 | {this.props.text} : 53 | this.props.text ? 54 | {this.props.text} : 55 | null 56 | } 57 | 58 | { 59 | this.props.rightView ? this._renderRightView() : {this.props.detailText} 60 | } 61 | 62 | { 63 | this.props.isRightArrowShow ? 64 | : null 68 | } 69 | 70 | 71 | ); 72 | } 73 | } 74 | 75 | const styles = StyleSheet.create({ 76 | container: { 77 | flexDirection: 'row', 78 | alignItems: 'center', 79 | height: 50, 80 | backgroundColor: 'white', 81 | }, 82 | circleIcon: { 83 | width: 24, 84 | height: 24, 85 | borderRadius: 12, 86 | marginLeft: 12, 87 | marginRight: 12, 88 | }, 89 | text: { 90 | fontSize: 16, 91 | color: 'black', 92 | }, 93 | centerWrapper: { 94 | flex: 1, 95 | flexDirection: 'row', 96 | justifyContent: 'flex-end', 97 | }, 98 | detailText: { 99 | flex: 1, 100 | textAlign: 'right', 101 | fontSize: 12, 102 | color: '#828282', 103 | }, 104 | icon: { 105 | tintColor: '#828282', 106 | marginLeft: 10, 107 | marginRight: 10, 108 | }, 109 | }); 110 | -------------------------------------------------------------------------------- /app/components/toast.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/10. 3 | */ 4 | import Toast from 'react-native-root-toast'; 5 | 6 | const defaultOptions = { 7 | duration: Toast.durations.SHORT, 8 | position: Toast.positions.BOTTOM, 9 | shadow: false, 10 | animation: true, 11 | hideOnPress: true, 12 | delay: 0, 13 | }; 14 | 15 | export const show = (message, option) => { 16 | return Toast.show(message, {...defaultOptions, ...option}); 17 | }; 18 | export const hide = Toast.hide; 19 | export default { 20 | show, 21 | hide, 22 | }; -------------------------------------------------------------------------------- /app/images/more_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/more_icon@2x.png -------------------------------------------------------------------------------- /app/images/more_icon@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/more_icon@3x.png -------------------------------------------------------------------------------- /app/images/tab_message_highlight_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/tab_message_highlight_icon@2x.png -------------------------------------------------------------------------------- /app/images/tab_message_highlight_icon@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/tab_message_highlight_icon@3x.png -------------------------------------------------------------------------------- /app/images/tab_message_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/tab_message_icon@2x.png -------------------------------------------------------------------------------- /app/images/tab_message_icon@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xsdlr/react-native-jmessage-example/7b07f9ed53bc94284c5ff511b8e0169c1f26b02b/app/images/tab_message_icon@3x.png -------------------------------------------------------------------------------- /app/layout/chatPage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/16. 3 | */ 4 | import React, { 5 | Component, 6 | PropTypes, 7 | } from 'react'; 8 | import { 9 | StyleSheet, 10 | StatusBar, 11 | View, 12 | Platform, 13 | Navigator, 14 | DeviceEventEmitter, 15 | } from 'react-native'; 16 | import JMessage from 'react-native-jmessage'; 17 | import NavigationBar from 'react-native-navigationbar'; 18 | import SeparatorLine from '../components/separatorLine'; 19 | import { GiftedChat } from 'react-native-gifted-chat'; 20 | import { isEmpty } from 'lodash'; 21 | import Toast from '../components/toast'; 22 | 23 | export default class ChatPage extends Component { 24 | static propTypes = { 25 | navigator: Navigator.propTypes.navigator, 26 | cid: PropTypes.string.isRequired, 27 | title: PropTypes.string.isRequired, 28 | }; 29 | state = { 30 | messages: [] 31 | }; 32 | componentWillMount() { 33 | JMessage.addReceiveMessageListener((message) => { 34 | console.log('receive', message); 35 | !this._unmount && this.setState((preState) => { 36 | return { 37 | messages: GiftedChat.append(preState.messages, this._transformMessage(message)), 38 | }; 39 | }); 40 | }); 41 | JMessage.historyMessages(this.props.cid, this.state.messages.length, 10).then((messages) => { 42 | console.log('messages', messages); 43 | const _messages = messages.map(this._transformMessage); 44 | this.setState({ 45 | messages: _messages 46 | }); 47 | }); 48 | JMessage.myInfo().then((info) => { 49 | this.setState({username: info.username}); 50 | }); 51 | JMessage.clearUnreadCount(this.props.cid).then((count) => { 52 | count > 0 && DeviceEventEmitter.emit('RefreshConversations'); 53 | }).done(); 54 | } 55 | 56 | componentWillUnmount() { 57 | JMessage.removeAllListener(); 58 | this._unmount = true; 59 | } 60 | onSend(messages = []) { 61 | for (const message of messages) { 62 | console.log('send message textInput', message); 63 | let type, data; 64 | if (message.text) { 65 | type = 'text'; 66 | data = {text: message.text}; 67 | } else if (message.image) { 68 | type = 'image'; 69 | data = {image: message.image}; 70 | } else { 71 | return; 72 | } 73 | JMessage.sendMessageByCID({ 74 | cid: this.props.cid, 75 | type: type, 76 | data: data, 77 | }).then((_msg) => { 78 | console.log('send message', _msg); 79 | this.setState((previousState) => { 80 | return { 81 | messages: GiftedChat.append(previousState.messages, [message]), 82 | }; 83 | }); 84 | }).catch(error => { 85 | const { code, message } = error; 86 | if(code == 803005) { 87 | Toast.show('您不在这个群中'); 88 | } else { 89 | Toast.show(message); 90 | } 91 | }); 92 | } 93 | } 94 | _transformMessage(message) { 95 | const {content={}, from={}, contentType=0} = message; 96 | const _message = {}; 97 | switch (contentType) { 98 | case 1: 99 | _message.text = content.text; 100 | break; 101 | case 2: 102 | _message.image = content.mediaLink; 103 | break; 104 | case 5: 105 | _message.text = `[事件]`; 106 | break; 107 | } 108 | return { 109 | ..._message, 110 | _id: message.msgId, 111 | serverId: message.serverMessageId, 112 | createdAt: new Date(message.timestamp), 113 | user: { 114 | _id: from.name, 115 | name: from.nickname || from.name, 116 | avatar: from.avatar, 117 | }, 118 | }; 119 | } 120 | _back() { 121 | this.props.navigator.pop(); 122 | } 123 | render() { 124 | return ( 125 | 126 | 133 | 143 | 144 | ); 145 | } 146 | } 147 | 148 | const styles = StyleSheet.create({ 149 | container: { 150 | flex: 1, 151 | backgroundColor: 'white' 152 | }, 153 | navBar: { 154 | top: 0, 155 | left: 0, 156 | right: 0, 157 | position: 'relative' 158 | }, 159 | }); 160 | -------------------------------------------------------------------------------- /app/layout/conversationListPage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2016/12/5. 3 | */ 4 | import React, { Component } from 'react'; 5 | import { 6 | StyleSheet, 7 | StatusBar, 8 | View, 9 | Platform, 10 | Navigator, 11 | Text, 12 | TouchableWithoutFeedback, 13 | ScrollView, 14 | RefreshControl, 15 | RecyclerViewBackedScrollView, 16 | ListView, 17 | DeviceEventEmitter, 18 | } from 'react-native'; 19 | import JMessage from 'react-native-jmessage'; 20 | import NavigationBar from 'react-native-navigationbar'; 21 | import SeparatorLine from '../components/separatorLine'; 22 | import ChatPage from './chatPage'; 23 | import Badge from '../components/badge'; 24 | 25 | export default class ConversationListPage extends Component { 26 | static propTypes = { 27 | navigator: Navigator.propTypes.navigator, 28 | }; 29 | dataSource = new ListView.DataSource({ 30 | rowHasChanged: (r1, r2) => r1 !== r2, 31 | }); 32 | state = { 33 | data: [], 34 | dataSource: this.dataSource.cloneWithRows([]), 35 | refreshing: false, 36 | }; 37 | componentDidMount() { 38 | this._mounted = true; 39 | JMessage.addReceiveMessageListener((message) => { 40 | console.log('message', message); 41 | this._onRefresh(); 42 | }); 43 | this.emitter = DeviceEventEmitter.addListener('RefreshConversations', this._onRefresh, this); 44 | this._onRefresh(); 45 | } 46 | 47 | componentWillUnmount() { 48 | this._mounted = false; 49 | JMessage.removeAllListener(); 50 | this.emitter.remove(); 51 | } 52 | render() { 53 | return ( 54 | 55 | 56 | 64 | { 65 | this._renderContent() 66 | } 67 | 68 | ); 69 | } 70 | _renderContent() { 71 | const isEmpty = (this.state.dataSource.getRowCount() === 0); 72 | if (isEmpty) { 73 | return( 74 | 87 | } 88 | > 89 | 90 | 91 | 暂时没有记录 92 | 93 | 94 | 95 | ); 96 | } else { 97 | return ( 98 | } 108 | renderSeparator={this._renderSeparator.bind(this)} 109 | refreshControl={ 110 | 117 | } 118 | />); 119 | } 120 | } 121 | _renderSeparator(sectionID, rowID) { 122 | return (); 123 | } 124 | _renderRow(data, sectionID, rowID) { 125 | return ( 126 | 127 | this._pressRow(data)}> 129 | 130 | 131 | {data.title||data.username} 132 | {data.laseMessage} 133 | 134 | { 135 | data.unreadCount > 0 ? 136 | 137 | {data.unreadCount} 138 | : null 139 | } 140 | 141 | 142 | 143 | ); 144 | } 145 | _onRefresh() { 146 | if (this.state.refreshing || !this._mounted) return; 147 | this.setState({refreshing: true}); 148 | JMessage.allConversations().then(data => { 149 | console.log('allConversations', data); 150 | if (!this._mounted) return; 151 | this.setState({ 152 | data, 153 | dataSource: this.state.dataSource.cloneWithRows(data), 154 | }); 155 | }).finally(() => this._mounted && this.setState({refreshing: false})); 156 | } 157 | _pressRow(data) { 158 | console.log('_pressRow', data); 159 | const {id, title} = data; 160 | this.props.navigator.push({ 161 | component: ChatPage, 162 | passProps: { 163 | cid: id, 164 | title: title, 165 | }, 166 | }); 167 | } 168 | } 169 | 170 | const styles = StyleSheet.create({ 171 | container: { 172 | flex: 1, 173 | backgroundColor: 'white' 174 | }, 175 | list: { 176 | flex: 1, 177 | justifyContent: 'center', 178 | alignItems: 'center', 179 | }, 180 | navBar: { 181 | top: 0, 182 | left: 0, 183 | right: 0, 184 | position: 'relative' 185 | }, 186 | }); 187 | -------------------------------------------------------------------------------- /app/layout/friendListPage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/10. 3 | */ 4 | import React, { Component } from 'react'; 5 | import { 6 | StyleSheet, 7 | View, 8 | Platform, 9 | } from 'react-native'; 10 | import JMessage from 'react-native-jmessage'; 11 | import NavigationBar from 'react-native-navigationbar'; 12 | 13 | export default class FriendListPage extends Component { 14 | componentDidMount() { 15 | JMessage.addReceiveMessageListener((message) => { 16 | console.log('receive', message); 17 | }); 18 | } 19 | componentWillUnmount() { 20 | JMessage.removeAllListener(); 21 | } 22 | render() { 23 | return ( 24 | 25 | 33 | 34 | 35 | ); 36 | } 37 | } 38 | 39 | const styles = StyleSheet.create({ 40 | container: { 41 | flex: 1, 42 | backgroundColor: 'white' 43 | }, 44 | }); -------------------------------------------------------------------------------- /app/layout/loginPage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by xsdlr on 2017/1/6. 3 | */ 4 | import React, { Component } from 'react'; 5 | import { 6 | StyleSheet, 7 | Text, 8 | View, 9 | Button, 10 | TextInput, 11 | Navigator, 12 | } from 'react-native'; 13 | import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard'; 14 | import JMessage from 'react-native-jmessage'; 15 | import SeparatorLine from '../components/separatorLine'; 16 | import Toast from '../components/toast'; 17 | import MainPage from './mainPage'; 18 | 19 | export default class LoginPage extends Component { 20 | static propTypes = { 21 | navigator: Navigator.propTypes.navigator, 22 | }; 23 | state = { 24 | account: '', 25 | password: '', 26 | isLoggedIn: false, 27 | }; 28 | componentWillMount() { 29 | JMessage.isLoggedIn().then((isLoggedIn) => { 30 | this.setState({isLoggedIn}); 31 | }); 32 | } 33 | render() { 34 | return ( 35 | 36 | 37 | this.refs['password'].focus()} 49 | onChangeText={this._accountChange.bind(this)} 50 | /> 51 | 52 | this.refs['password'].focus()} 64 | onChangeText={this._passwordChange.bind(this)} 65 | /> 66 | 67 | 68 |