Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 9595385

Browse files
authored
Merge pull request #3 from hudl/enhancement-SampleApp
Sample App for React Fragment
2 parents 2b92d8f + 0d9ac1a commit 9595385

26 files changed

+333
-1
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ Fragment messagingFragment = new ReactFragment.Builder()
3737
.setLaunchOptions(launchOptions) // A Bundle of launch options
3838
.build();
3939
```
40+
41+
## Running Sample App
42+
43+
NOTE: Make sure your environment is set up for [React Native](https://facebook.github.io/react-native/docs/getting-started.html) and [Android](https://developer.android.com/training/index.html) development.
44+
45+
- Clone the repo
46+
- Open a terminal and navigate to the root directory of your checkout
47+
- `cd sample-app`
48+
- `yarn`
49+
- Open the project in Android Studio and let everything build
50+
- Back in your terminal run `react-native start`
51+
- In Android Studio run the `app` on an emulator or your device

sample-app/android/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample-app/android/app/build.gradle

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.3"
6+
7+
defaultConfig {
8+
applicationId "com.hudl.oss.react.sampleapp"
9+
minSdkVersion 16
10+
targetSdkVersion 25
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
repositories {
26+
maven {
27+
// All of React Native (JS, Android binaries) is installed from npm
28+
url "$rootDir/sample-app/node_modules/react-native/android"
29+
}
30+
flatDir {
31+
dirs "$rootDir/react-native-android-fragment/libs"
32+
}
33+
}
34+
35+
dependencies {
36+
compile fileTree(dir: 'libs', include: ['*.jar'])
37+
38+
compile project(':react-native-android-fragment')
39+
40+
compile "com.facebook.react:react-native:0.43.2"
41+
42+
compile 'com.android.support:appcompat-v7:25.3.1'
43+
compile 'com.android.support.constraint:constraint-layout:1.0.1'
44+
testCompile 'junit:junit:4.12'
45+
}
46+
47+
// Run this once to be able to run the application with BUCK
48+
// puts all compile dependencies into folder libs for BUCK to use
49+
task copyDownloadableDepsToLibs(type: Copy) {
50+
from configurations.compile
51+
into 'libs'
52+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/brent.kelly/Library/Android/sdk/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+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.hudl.oss.react.sampleapp;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.hudl.oss.react.sampleapp", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hudl.oss.react.sampleapp">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:name=".MainApplication"
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
23+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
24+
</application>
25+
26+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.hudl.oss.react.sampleapp;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
6+
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
7+
import com.hudl.oss.react.fragment.ReactFragment;
8+
9+
public class MainActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
10+
11+
private static final String COMPONENT_NAME = "SampleApp";
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
18+
if (savedInstanceState == null) {
19+
ReactFragment reactFragment = new ReactFragment.Builder(COMPONENT_NAME).build();
20+
21+
getSupportFragmentManager()
22+
.beginTransaction()
23+
.add(R.id.container_main, reactFragment)
24+
.commit();
25+
}
26+
}
27+
28+
@Override
29+
public void invokeDefaultOnBackPressed() {
30+
super.onBackPressed();
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.hudl.oss.react.sampleapp;
2+
3+
import android.app.Application;
4+
5+
import com.facebook.react.ReactApplication;
6+
import com.facebook.react.ReactNativeHost;
7+
import com.facebook.react.ReactPackage;
8+
import com.facebook.react.shell.MainReactPackage;
9+
import com.facebook.soloader.SoLoader;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
public class MainApplication extends Application implements ReactApplication {
15+
16+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
17+
@Override
18+
public boolean getUseDeveloperSupport() {
19+
return BuildConfig.DEBUG;
20+
}
21+
22+
@Override
23+
protected List<ReactPackage> getPackages() {
24+
return Arrays.<ReactPackage>asList(
25+
new MainReactPackage()
26+
);
27+
}
28+
};
29+
30+
@Override
31+
public ReactNativeHost getReactNativeHost() {
32+
return mReactNativeHost;
33+
}
34+
35+
@Override
36+
public void onCreate() {
37+
super.onCreate();
38+
SoLoader.init(this, /* native exopackage */ false);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/container_main"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"/>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">SampleApp</string>
3+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
10+
11+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.hudl.oss.react.sampleapp;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() throws Exception {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

sample-app/index.android.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
* @flow
5+
*/
6+
7+
import React, { Component } from 'react';
8+
import {
9+
AppRegistry,
10+
StyleSheet,
11+
Text,
12+
View
13+
} from 'react-native';
14+
15+
export default class SampleApp extends Component {
16+
render() {
17+
return (
18+
<View style={styles.container}>
19+
<Text style={styles.welcome}>
20+
Welcome to React Native!
21+
</Text>
22+
<Text style={styles.instructions}>
23+
To get started, edit index.android.js
24+
</Text>
25+
<Text style={styles.instructions}>
26+
Double tap R on your keyboard to reload,{'\n'}
27+
Shake or press menu button for dev menu
28+
</Text>
29+
</View>
30+
);
31+
}
32+
}
33+
34+
const styles = StyleSheet.create({
35+
container: {
36+
flex: 1,
37+
justifyContent: 'center',
38+
alignItems: 'center',
39+
backgroundColor: '#F5FCFF',
40+
},
41+
welcome: {
42+
fontSize: 20,
43+
textAlign: 'center',
44+
margin: 10,
45+
},
46+
instructions: {
47+
textAlign: 'center',
48+
color: '#333333',
49+
marginBottom: 5,
50+
},
51+
});
52+
53+
AppRegistry.registerComponent('SampleApp', () => SampleApp);

sample-app/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "SampleApp",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"start": "node node_modules/react-native/local-cli/cli.js start",
7+
"test": "jest"
8+
},
9+
"dependencies": {
10+
"react": "16.0.0-alpha.6",
11+
"react-native": "0.43.2"
12+
},
13+
"devDependencies": {
14+
"babel-jest": "20.0.3",
15+
"babel-preset-react-native": "1.9.2",
16+
"jest": "20.0.4",
17+
"react-test-renderer": "16.0.0-alpha.6"
18+
},
19+
"jest": {
20+
"preset": "react-native"
21+
}
22+
}

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
rootProject.name = 'ReactNative-Android-Fragment'
22

3-
include ':react-native-android-fragment'
3+
include ':react-native-android-fragment', ':sample-app/android:app'
44

0 commit comments

Comments
 (0)