Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nihgwu committed Aug 24, 2016
1 parent 67e7463 commit 70715cf
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
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
120 changes: 120 additions & 0 deletions README.md
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,
});
```
20 changes: 20 additions & 0 deletions android/build.gradle
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:+'
}
4 changes: 4 additions & 0 deletions android/src/main/AndroidManifest.xml
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>
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;
}
}
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();
}

}
7 changes: 7 additions & 0 deletions index.js
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;
Loading

0 comments on commit 70715cf

Please sign in to comment.