Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit a727c9b

Browse files
author
Elad Gil
committed
added test app
1 parent 90af609 commit a727c9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+9894
-4
lines changed

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["react-native"]
3-
}
2+
"presets": ["module:metro-react-native-babel-preset"]
3+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@
4343
"react-native": ">=0.41.2"
4444
},
4545
"devDependencies": {
46-
"babel-eslint": "^8.2.5",
4746
"eslint": "^4.19.1",
4847
"jest": "^23.1.0",
49-
"react-native": "^0.55.4"
48+
"metro-react-native-babel-preset": "0.48.5",
49+
"react-native": "^0.57.8",
50+
"react": "16.6.3"
5051
},
5152
"jest": {
5253
"preset": "react-native",

testApp/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

testApp/App.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
*
5+
* @format
6+
* @flow
7+
*/
8+
9+
import React, { Component } from 'react';
10+
import { StyleSheet, Text, SafeAreaView, TextInput, Button } from 'react-native';
11+
import RNBGD from '../index';
12+
13+
const testURL = 'https://speed.hetzner.de/100MB.bin';
14+
const urlRegex = /^(?:https?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/;
15+
16+
function isValid(url) {
17+
return urlRegex.test(url);
18+
}
19+
20+
const styles = StyleSheet.create({
21+
container: {
22+
flex: 1,
23+
justifyContent: 'center',
24+
alignItems: 'center',
25+
backgroundColor: '#F5FCFF',
26+
paddingHorizontal: 10
27+
},
28+
textInput: {
29+
height: 70,
30+
width: 300,
31+
borderColor: 'grey',
32+
borderWidth: 1,
33+
padding: 10
34+
}
35+
});
36+
37+
export default class App extends Component {
38+
state = {
39+
url: '',
40+
status: 'idle',
41+
percent: 0
42+
};
43+
44+
handleClick() {
45+
if (this.state.status === 'idle') {
46+
this.downloadTask = RNBGD.download({
47+
id: 'task',
48+
url: this.state.url || testURL,
49+
destination: `${RNBGD.directories.documents}/file`
50+
}).begin(expectedBytes => {
51+
this.setState({ totalBytes: expectedBytes });
52+
})
53+
.progress(percent => {
54+
this.setState({ percent });
55+
})
56+
.done(() => {
57+
this.setState({ status: 'idle', percent: 0 });
58+
})
59+
.error(err => {
60+
console.log(err);
61+
this.setState({ status: 'idle', percent: 0 });
62+
});
63+
64+
this.setState({ status: 'downloading' });
65+
} else if (this.state.status === 'downloading') {
66+
this.downloadTask.pause();
67+
this.setState({ status: 'paused' });
68+
} else if (this.state.status === 'paused') {
69+
this.downloadTask.resume();
70+
this.setState({ status: 'downloading' });
71+
}
72+
}
73+
74+
render() {
75+
let buttonLabel = 'Download';
76+
if (this.state.status === 'downloading') {
77+
buttonLabel = 'Pause';
78+
} else if (this.state.status === 'paused') {
79+
buttonLabel = 'Resume';
80+
}
81+
82+
return (
83+
<SafeAreaView style={styles.container}>
84+
<TextInput
85+
style={styles.textInput}
86+
textContentType="none"
87+
autoCorrect={false}
88+
multiline={true}
89+
keyboardType="url"
90+
placeholder={testURL}
91+
onChangeText={(text) => { this.setState({ url: text.toLowerCase() }); }}
92+
value={this.state.url}
93+
/>
94+
<Button
95+
title={buttonLabel}
96+
onPress={this.handleClick.bind(this)}
97+
disabled={this.state.url !== '' && !isValid(this.state.url)}
98+
/>
99+
<Text>Status: {this.state.status}</Text>
100+
<Text>Downloading: {this.state.percent * 100}%</Text>
101+
</SafeAreaView>
102+
);
103+
}
104+
}

testApp/android/app/BUCK

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# To learn about Buck see [Docs](https://buckbuild.com/).
2+
# To run your application with Buck:
3+
# - install Buck
4+
# - `npm start` - to start the packager
5+
# - `cd android`
6+
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8+
# - `buck install -r android/app` - compile, install and run application
9+
#
10+
11+
lib_deps = []
12+
13+
for jarfile in glob(['libs/*.jar']):
14+
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15+
lib_deps.append(':' + name)
16+
prebuilt_jar(
17+
name = name,
18+
binary_jar = jarfile,
19+
)
20+
21+
for aarfile in glob(['libs/*.aar']):
22+
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23+
lib_deps.append(':' + name)
24+
android_prebuilt_aar(
25+
name = name,
26+
aar = aarfile,
27+
)
28+
29+
android_library(
30+
name = "all-libs",
31+
exported_deps = lib_deps,
32+
)
33+
34+
android_library(
35+
name = "app-code",
36+
srcs = glob([
37+
"src/main/java/**/*.java",
38+
]),
39+
deps = [
40+
":all-libs",
41+
":build_config",
42+
":res",
43+
],
44+
)
45+
46+
android_build_config(
47+
name = "build_config",
48+
package = "com.testapp",
49+
)
50+
51+
android_resource(
52+
name = "res",
53+
package = "com.testapp",
54+
res = "src/main/res",
55+
)
56+
57+
android_binary(
58+
name = "app",
59+
keystore = "//android/keystores:debug",
60+
manifest = "src/main/AndroidManifest.xml",
61+
package_type = "debug",
62+
deps = [
63+
":app-code",
64+
],
65+
)

testApp/android/app/build.gradle

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
* // whether to disable dev mode in custom build variants (by default only disabled in release)
37+
* // for example: to disable dev mode in the staging build type (if configured)
38+
* devDisabledInStaging: true,
39+
* // The configuration property can be in the following formats
40+
* // 'devDisabledIn${productFlavor}${buildType}'
41+
* // 'devDisabledIn${buildType}'
42+
*
43+
* // the root of your project, i.e. where "package.json" lives
44+
* root: "../../",
45+
*
46+
* // where to put the JS bundle asset in debug mode
47+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48+
*
49+
* // where to put the JS bundle asset in release mode
50+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51+
*
52+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
53+
* // require('./image.png')), in debug mode
54+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55+
*
56+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
57+
* // require('./image.png')), in release mode
58+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59+
*
60+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
63+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64+
* // for example, you might want to remove it from here.
65+
* inputExcludes: ["android/**", "ios/**"],
66+
*
67+
* // override which node gets called and with what additional arguments
68+
* nodeExecutableAndArgs: ["node"],
69+
*
70+
* // supply additional arguments to the packager
71+
* extraPackagerArgs: []
72+
* ]
73+
*/
74+
75+
project.ext.react = [
76+
entryFile: "index.js"
77+
]
78+
79+
project.ext.react = [
80+
cliPath: "node_modules/haul/bin/cli.js"
81+
]
82+
83+
apply from: "../../node_modules/react-native/react.gradle"
84+
85+
/**
86+
* Set this to true to create two separate APKs instead of one:
87+
* - An APK that only works on ARM devices
88+
* - An APK that only works on x86 devices
89+
* The advantage is the size of the APK is reduced by about 4MB.
90+
* Upload all the APKs to the Play Store and people will download
91+
* the correct one based on the CPU architecture of their device.
92+
*/
93+
def enableSeparateBuildPerCPUArchitecture = false
94+
95+
/**
96+
* Run Proguard to shrink the Java bytecode in release builds.
97+
*/
98+
def enableProguardInReleaseBuilds = false
99+
100+
android {
101+
compileSdkVersion rootProject.ext.compileSdkVersion
102+
buildToolsVersion rootProject.ext.buildToolsVersion
103+
104+
defaultConfig {
105+
applicationId "com.testapp"
106+
minSdkVersion rootProject.ext.minSdkVersion
107+
targetSdkVersion rootProject.ext.targetSdkVersion
108+
versionCode 1
109+
versionName "1.0"
110+
ndk {
111+
abiFilters "armeabi-v7a", "x86"
112+
}
113+
}
114+
splits {
115+
abi {
116+
reset()
117+
enable enableSeparateBuildPerCPUArchitecture
118+
universalApk false // If true, also generate a universal APK
119+
include "armeabi-v7a", "x86"
120+
}
121+
}
122+
buildTypes {
123+
release {
124+
minifyEnabled enableProguardInReleaseBuilds
125+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
126+
}
127+
}
128+
// applicationVariants are e.g. debug, release
129+
applicationVariants.all { variant ->
130+
variant.outputs.each { output ->
131+
// For each separate APK per architecture, set a unique version code as described here:
132+
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
133+
def versionCodes = ["armeabi-v7a":1, "x86":2]
134+
def abi = output.getFilter(OutputFile.ABI)
135+
if (abi != null) { // null for the universal-debug, universal-release variants
136+
output.versionCodeOverride =
137+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
138+
}
139+
}
140+
}
141+
}
142+
143+
dependencies {
144+
compile project(':react-native-background-downloader')
145+
implementation fileTree(dir: "libs", include: ["*.jar"])
146+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
147+
implementation "com.facebook.react:react-native:+" // From node_modules
148+
}
149+
150+
// Run this once to be able to run the application with BUCK
151+
// puts all compile dependencies into folder libs for BUCK to use
152+
task copyDownloadableDepsToLibs(type: Copy) {
153+
from configurations.compile
154+
into 'libs'
155+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
#}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.testapp">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6+
7+
<application
8+
android:name=".MainApplication"
9+
android:label="@string/app_name"
10+
android:icon="@mipmap/ic_launcher"
11+
android:allowBackup="false"
12+
android:theme="@style/AppTheme">
13+
<activity
14+
android:name=".MainActivity"
15+
android:label="@string/app_name"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
17+
android:windowSoftInputMode="adjustResize">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
24+
</application>
25+
26+
</manifest>

0 commit comments

Comments
 (0)