-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
595 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IJ | ||
# | ||
*.iml | ||
.idea | ||
.gradle | ||
local.properties | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# react-native-leancloud | ||
|
||
a react native component for [leancloud javascript-sdk](https://github.com/leancloud/javascript-sdk) | ||
|
||
this component simply move the `appId` and `appKey` from the javascript file to native code as it's really easy to get those values from the `js.bundle` in released app. | ||
|
||
## Install | ||
|
||
**you have to install [leancloud javascript-sdk](https://github.com/leancloud/javascript-sdk) first** | ||
|
||
```shell | ||
npm install nihgwu/react-native-leancloud --save | ||
``` | ||
|
||
## Automatically link | ||
|
||
#### With React Native 0.27+ | ||
|
||
```shell | ||
react-native link react-native-leancloud | ||
``` | ||
|
||
#### With older versions of React Native | ||
|
||
You need [`rnpm`](https://github.com/rnpm/rnpm) (`npm install -g rnpm`) | ||
|
||
```shell | ||
rnpm link react-native-leancloud | ||
``` | ||
|
||
## Manually link | ||
|
||
### iOS | ||
|
||
In XCode, in the project navigator: | ||
- Right click _Libraries_ | ||
- Add Files to _[your project's name]_ | ||
- Go to `node_modules/react-native-leancloud/ios` | ||
- Add the `.xcodeproj` file | ||
|
||
In XCode, in the project navigator, select your project. | ||
- Add the `libRNLeanCloud.a` from the _deviceinfo_ project to your project's _Build Phases ➜ Link Binary With Libraries_ | ||
- Click `.xcodeproj` file you added before in the project navigator and go the _Build Settings_ tab. Make sure _All_ is toggled on (instead of _Basic_). | ||
- Look for _Header Search Paths_ and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` | ||
- Mark both as recursive (should be OK by default). | ||
|
||
Run your project (Cmd+R) | ||
|
||
### Android | ||
|
||
#### With React Native 0.29+ | ||
|
||
- in `MainApplication.java`: | ||
|
||
```diff | ||
+ import com.liteneo.RNLeanCloud.RNLeanCloudPackage; | ||
|
||
public class MainApplication extends Application implements ReactApplication { | ||
//...... | ||
|
||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
return Arrays.<ReactPackage>asList( | ||
+ new RNLeanCloudPackage("your leancloud appId", "your leancloud appKey"), | ||
new MainReactPackage() | ||
); | ||
} | ||
|
||
...... | ||
} | ||
``` | ||
|
||
#### With older versions of React Native: | ||
|
||
- in `MainActivity.java`: | ||
|
||
```diff | ||
+ import com.liteneo.RNLeanCloud.RNLeanCloudPackage; | ||
|
||
public class MainActivity extends ReactActivity { | ||
...... | ||
|
||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
return Arrays.<ReactPackage>asList( | ||
+ new RNLeanCloudPackage("your leancloud appId", "your leancloud appKey"), | ||
new MainReactPackage() | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
### iOS | ||
|
||
- in `info.plist` | ||
|
||
```diff | ||
+ <key>LeanCloudAppId</key> | ||
+ <string>your leancloud appId</string> | ||
+ <key>LeanCloudAppKey</key> | ||
+ <string>your leancloud appKey</string> | ||
``` | ||
|
||
### Android | ||
|
||
see [Manually link for Android](#android) | ||
|
||
## Usage | ||
|
||
```js | ||
import AV from 'leancloud-storage'; | ||
import RNLeanCloud from 'react-native-leancloud'; | ||
|
||
AV.init({ | ||
appId: RNLeanCloud.appId, | ||
appKey: RNLeanCloud.appKey, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
dependencies { | ||
compile 'com.facebook.react:react-native:+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.liteneo.RNLeanCloud" > | ||
</manifest> |
32 changes: 32 additions & 0 deletions
32
android/src/main/java/com/liteneo/RNLeanCloud/RNLeanCloudModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.liteneo.RNLeanCloud; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class RNLeanCloudModule extends ReactContextBaseJavaModule { | ||
|
||
private String mAppId; | ||
private String mAppKey; | ||
|
||
public RNLeanCloudModule(ReactApplicationContext reactContext, String appId, String appKey) { | ||
super(reactContext); | ||
this.mAppId = appId; | ||
this.mAppKey = appKey; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RNLeanCloud"; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getConstants() { | ||
final Map<String, Object> constants = new HashMap<>(); | ||
constants.put("appId", mAppId); | ||
constants.put("appKey", mAppKey); | ||
return constants; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
android/src/main/java/com/liteneo/RNLeanCloud/RNLeanCloudPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.liteneo.RNLeanCloud; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RNLeanCloudPackage implements ReactPackage { | ||
|
||
private String mAppId; | ||
private String mAppKey; | ||
|
||
public RNLeanCloudPackage(String appId, String appKey) { | ||
this.mAppId = appId; | ||
this.mAppKey = appKey; | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules( | ||
ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new RNLeanCloudModule(reactContext, this.mAppId, this.mAppKey)); | ||
|
||
return modules; | ||
} | ||
|
||
@Override | ||
public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers( | ||
ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
import { NativeModules } from 'react-native'; | ||
|
||
const { RNLeanCloud } = NativeModules; | ||
|
||
export default RNLeanCloud; |
Oops, something went wrong.