Skip to content

Commit

Permalink
scaffolded library
Browse files Browse the repository at this point in the history
  • Loading branch information
evanjmg committed Feb 23, 2018
0 parents commit b0d29f3
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 0 deletions.
Empty file added .gitattributes
Empty file.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# OSX
#
.DS_Store

# node.js
#
node_modules/
npm-debug.log
yarn-error.log


# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# BUCK
buck-out/
\.buckd/
*.keystore

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# react-native-home-pressed

## Getting started

`$ npm install react-native-home-pressed --save`

### Mostly automatic installation

`$ react-native link react-native-home-pressed`

### Manual installation


#### Android

1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.reactlibrary.RNHomePressedPackage;` to the imports at the top of the file
- Add `new RNHomePressedPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-home-pressed'
project(':react-native-home-pressed').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-home-pressed/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-home-pressed')
```


## Usage
```javascript
import RNHomePressed from 'react-native-home-pressed';

// TODO: What to do with the module?
RNHomePressed;
```

36 changes: 36 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

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
}
}

repositories {
mavenCentral()
}

dependencies {
compile 'com.facebook.react:react-native:+'
}

6 changes: 6 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactlibrary">

</manifest>

25 changes: 25 additions & 0 deletions android/src/main/java/com/reactlibrary/RNHomePressedModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

package com.reactlibrary;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;

public class RNHomePressedModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;

public RNHomePressedModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@ReactMethod
public void onHomePressed(Callback callback) {
callback.invoke()
}
@Override
public String getName() {
return "RNHomePressed";
}
}
28 changes: 28 additions & 0 deletions android/src/main/java/com/reactlibrary/RNHomePressedPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

package com.reactlibrary;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

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;
public class RNHomePressedPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNHomePressedModule(reactContext));
}

// Deprecated from RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import { NativeModules } from 'react-native';

const { RNHomePressed } = NativeModules;

export default RNHomePressed;
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{
"name": "react-native-home-pressed",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"react-native"
],
"author": "",
"license": "",
"peerDependencies": {
"react-native": "^0.41.2"
}
}

0 comments on commit b0d29f3

Please sign in to comment.