Skip to content

Commit 2b9afa0

Browse files
committed
Add a real example that loads into a bundle of choice using react-native-fs.
1 parent f4d06f5 commit 2b9afa0

File tree

6 files changed

+100
-32
lines changed

6 files changed

+100
-32
lines changed

example/App.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,52 @@ import React, { Component } from 'react';
88
import {
99
Platform,
1010
StyleSheet,
11-
Text,
1211
View,
1312
Button,
13+
TextInput
1414
} from 'react-native';
1515
import RNDynamicBundle from 'react-native-dynamic-bundle';
16-
17-
const instructions = Platform.select({
18-
ios: 'Press Cmd+R to reload,\n' +
19-
'Cmd+D or shake for dev menu',
20-
android: 'Double tap R on your keyboard to reload,\n' +
21-
'Shake or press menu button for dev menu',
22-
});
16+
import RNFS from 'react-native-fs';
2317

2418
type Props = {};
2519
export default class App extends Component<Props> {
20+
constructor(props) {
21+
super(props);
22+
23+
this.state = {
24+
url: ""
25+
}
26+
}
27+
2628
componentWillMount = () => {
2729

2830
}
2931

3032
render() {
3133
return (
3234
<View style={styles.container}>
33-
<Text style={styles.welcome}>
34-
Welcome to React Native!
35-
</Text>
36-
<Text style={styles.instructions}>
37-
To get started, edit App.js
38-
</Text>
39-
<Text style={styles.instructions}>
40-
{instructions}
41-
</Text>
42-
<Button onPress={this._onReloadButtonPress} title="RELOAD"/>
35+
<TextInput
36+
style={styles.textInput}
37+
onChangeText={(url) => { this.setState({ url });}}
38+
value={this.state.url}
39+
autocorrect={false}
40+
placeholder="URL"
41+
autoCapitalize="none"
42+
/>
43+
<Button onPress={this._onReloadButtonPress} title="LOAD"/>
4344
</View>
4445
);
4546
}
4647

47-
_onReloadButtonPress = () =>{
48-
RNDynamicBundle.registerBundle("yolo", "trolo.bundle")
49-
RNDynamicBundle.setActiveBundle("yolo");
48+
_onReloadButtonPress = async () => {
49+
const { promise } = RNFS.downloadFile({
50+
fromUrl: this.state.url,
51+
toFile: RNFS.DocumentDirectoryPath + "/test.bundle",
52+
});
53+
const result = await promise;
54+
55+
RNDynamicBundle.registerBundle('test', 'test.bundle');
56+
RNDynamicBundle.setActiveBundle('test');
5057
RNDynamicBundle.reloadBundle();
5158
}
5259
}
@@ -58,14 +65,10 @@ const styles = StyleSheet.create({
5865
alignItems: 'center',
5966
backgroundColor: '#F5FCFF',
6067
},
61-
welcome: {
62-
fontSize: 20,
63-
textAlign: 'center',
64-
margin: 10,
65-
},
66-
instructions: {
67-
textAlign: 'center',
68-
color: '#333333',
69-
marginBottom: 5,
70-
},
68+
textInput: {
69+
width: 250,
70+
height: 40,
71+
borderColor: 'gray',
72+
borderWidth: 1,
73+
}
7174
});

example/android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ android {
137137
}
138138

139139
dependencies {
140+
compile project(':react-native-fs')
140141
compile project(':react-native-dynamic-bundle')
141142
compile fileTree(dir: "libs", include: ["*.jar"])
142143
compile "com.android.support:appcompat-v7:23.0.1"

example/android/app/src/main/java/com/example/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.util.Log;
55

66
import com.facebook.react.ReactApplication;
7+
import com.rnfs.RNFSPackage;
78

89
import org.mauritsd.reactnativedynamicbundle.RNDynamicBundleModule;
910
import org.mauritsd.reactnativedynamicbundle.RNDynamicBundlePackage;
@@ -30,6 +31,7 @@ public boolean getUseDeveloperSupport() {
3031
protected List<ReactPackage> getPackages() {
3132
return Arrays.<ReactPackage>asList(
3233
new MainReactPackage(),
34+
new RNFSPackage(),
3335
new RNDynamicBundlePackage()
3436
);
3537
}

example/android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
rootProject.name = 'example'
2+
include ':react-native-fs'
3+
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
24
include ':react-native-dynamic-bundle'
35
project(':react-native-dynamic-bundle').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-dynamic-bundle/android')
46

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; };
1414
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; };
1515
00E356F31AD99517003FC87E /* exampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* exampleTests.m */; };
16+
01A42B839AB7480E96E12028 /* libRNFS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21A29B5DF8F744DCB1356361 /* libRNFS.a */; };
1617
133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; };
1718
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; };
1819
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */; };
@@ -258,6 +259,20 @@
258259
remoteGlobalIDString = 358F4ED71D1E81A9004DF814;
259260
remoteInfo = RCTBlob;
260261
};
262+
F60721D9205B2E6000057CC4 /* PBXContainerItemProxy */ = {
263+
isa = PBXContainerItemProxy;
264+
containerPortal = F9E82F2080F04CD896F3F8AD /* RNFS.xcodeproj */;
265+
proxyType = 2;
266+
remoteGlobalIDString = F12AFB9B1ADAF8F800E0535D;
267+
remoteInfo = RNFS;
268+
};
269+
F60721DB205B2E6000057CC4 /* PBXContainerItemProxy */ = {
270+
isa = PBXContainerItemProxy;
271+
containerPortal = F9E82F2080F04CD896F3F8AD /* RNFS.xcodeproj */;
272+
proxyType = 2;
273+
remoteGlobalIDString = 6456441F1EB8DA9100672408;
274+
remoteInfo = "RNFS-tvOS";
275+
};
261276
F673FEED205943AB00615D62 /* PBXContainerItemProxy */ = {
262277
isa = PBXContainerItemProxy;
263278
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
@@ -343,6 +358,7 @@
343358
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = example/Info.plist; sourceTree = "<group>"; };
344359
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = example/main.m; sourceTree = "<group>"; };
345360
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
361+
21A29B5DF8F744DCB1356361 /* libRNFS.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNFS.a; sourceTree = "<group>"; };
346362
2D02E47B1E0B4A5D006451C7 /* example-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
347363
2D02E4901E0B4A5D006451C7 /* example-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "example-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
348364
2D16E6891FA4F8E400B85C8A /* libReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libReact.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -352,6 +368,7 @@
352368
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
353369
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
354370
F05D9495E3B6402597A433B7 /* libRNDynamicBundle.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNDynamicBundle.a; sourceTree = "<group>"; };
371+
F9E82F2080F04CD896F3F8AD /* RNFS.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFS.xcodeproj; path = "../node_modules/react-native-fs/RNFS.xcodeproj"; sourceTree = "<group>"; };
355372
/* End PBXFileReference section */
356373

357374
/* Begin PBXFrameworksBuildPhase section */
@@ -381,6 +398,7 @@
381398
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
382399
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
383400
CE5FACED68C04E1597F4A34D /* libRNDynamicBundle.a in Frameworks */,
401+
01A42B839AB7480E96E12028 /* libRNFS.a in Frameworks */,
384402
);
385403
runOnlyForDeploymentPostprocessing = 0;
386404
};
@@ -567,6 +585,7 @@
567585
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
568586
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
569587
74DDF5076E184A01838A5872 /* RNDynamicBundle.xcodeproj */,
588+
F9E82F2080F04CD896F3F8AD /* RNFS.xcodeproj */,
570589
);
571590
name = Libraries;
572591
sourceTree = "<group>";
@@ -615,10 +634,20 @@
615634
name = Products;
616635
sourceTree = "<group>";
617636
};
637+
F60721D5205B2E5C00057CC4 /* Products */ = {
638+
isa = PBXGroup;
639+
children = (
640+
F60721DA205B2E6000057CC4 /* libRNFS.a */,
641+
F60721DC205B2E6000057CC4 /* libRNFS.a */,
642+
);
643+
name = Products;
644+
sourceTree = "<group>";
645+
};
618646
F673FEC7205943AA00615D62 /* Recovered References */ = {
619647
isa = PBXGroup;
620648
children = (
621649
F05D9495E3B6402597A433B7 /* libRNDynamicBundle.a */,
650+
21A29B5DF8F744DCB1356361 /* libRNFS.a */,
622651
);
623652
name = "Recovered References";
624653
sourceTree = "<group>";
@@ -794,6 +823,10 @@
794823
ProductGroup = F673FEFD205943AD00615D62 /* Products */;
795824
ProjectRef = 74DDF5076E184A01838A5872 /* RNDynamicBundle.xcodeproj */;
796825
},
826+
{
827+
ProductGroup = F60721D5205B2E5C00057CC4 /* Products */;
828+
ProjectRef = F9E82F2080F04CD896F3F8AD /* RNFS.xcodeproj */;
829+
},
797830
);
798831
projectRoot = "";
799832
targets = (
@@ -1009,6 +1042,20 @@
10091042
remoteRef = ADBDB9261DFEBF0700ED6528 /* PBXContainerItemProxy */;
10101043
sourceTree = BUILT_PRODUCTS_DIR;
10111044
};
1045+
F60721DA205B2E6000057CC4 /* libRNFS.a */ = {
1046+
isa = PBXReferenceProxy;
1047+
fileType = archive.ar;
1048+
path = libRNFS.a;
1049+
remoteRef = F60721D9205B2E6000057CC4 /* PBXContainerItemProxy */;
1050+
sourceTree = BUILT_PRODUCTS_DIR;
1051+
};
1052+
F60721DC205B2E6000057CC4 /* libRNFS.a */ = {
1053+
isa = PBXReferenceProxy;
1054+
fileType = archive.ar;
1055+
path = libRNFS.a;
1056+
remoteRef = F60721DB205B2E6000057CC4 /* PBXContainerItemProxy */;
1057+
sourceTree = BUILT_PRODUCTS_DIR;
1058+
};
10121059
F673FEEE205943AB00615D62 /* libjsinspector.a */ = {
10131060
isa = PBXReferenceProxy;
10141061
fileType = archive.ar;
@@ -1213,13 +1260,15 @@
12131260
HEADER_SEARCH_PATHS = (
12141261
"$(inherited)",
12151262
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1263+
"$(SRCROOT)/../node_modules/react-native-fs/**",
12161264
);
12171265
INFOPLIST_FILE = exampleTests/Info.plist;
12181266
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
12191267
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
12201268
LIBRARY_SEARCH_PATHS = (
12211269
"$(inherited)",
12221270
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1271+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12231272
);
12241273
OTHER_LDFLAGS = (
12251274
"-ObjC",
@@ -1238,13 +1287,15 @@
12381287
HEADER_SEARCH_PATHS = (
12391288
"$(inherited)",
12401289
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1290+
"$(SRCROOT)/../node_modules/react-native-fs/**",
12411291
);
12421292
INFOPLIST_FILE = exampleTests/Info.plist;
12431293
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
12441294
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
12451295
LIBRARY_SEARCH_PATHS = (
12461296
"$(inherited)",
12471297
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1298+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12481299
);
12491300
OTHER_LDFLAGS = (
12501301
"-ObjC",
@@ -1264,6 +1315,7 @@
12641315
HEADER_SEARCH_PATHS = (
12651316
"$(inherited)",
12661317
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1318+
"$(SRCROOT)/../node_modules/react-native-fs/**",
12671319
);
12681320
INFOPLIST_FILE = example/Info.plist;
12691321
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1285,6 +1337,7 @@
12851337
HEADER_SEARCH_PATHS = (
12861338
"$(inherited)",
12871339
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1340+
"$(SRCROOT)/../node_modules/react-native-fs/**",
12881341
);
12891342
INFOPLIST_FILE = example/Info.plist;
12901343
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1313,12 +1366,14 @@
13131366
HEADER_SEARCH_PATHS = (
13141367
"$(inherited)",
13151368
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1369+
"$(SRCROOT)/../node_modules/react-native-fs/**",
13161370
);
13171371
INFOPLIST_FILE = "example-tvOS/Info.plist";
13181372
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
13191373
LIBRARY_SEARCH_PATHS = (
13201374
"$(inherited)",
13211375
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1376+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13221377
);
13231378
OTHER_LDFLAGS = (
13241379
"-ObjC",
@@ -1347,12 +1402,14 @@
13471402
HEADER_SEARCH_PATHS = (
13481403
"$(inherited)",
13491404
"$(SRCROOT)/../node_modules/react-native-dynamic-bundle/ios/**",
1405+
"$(SRCROOT)/../node_modules/react-native-fs/**",
13501406
);
13511407
INFOPLIST_FILE = "example-tvOS/Info.plist";
13521408
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
13531409
LIBRARY_SEARCH_PATHS = (
13541410
"$(inherited)",
13551411
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1412+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13561413
);
13571414
OTHER_LDFLAGS = (
13581415
"-ObjC",
@@ -1382,6 +1439,7 @@
13821439
LIBRARY_SEARCH_PATHS = (
13831440
"$(inherited)",
13841441
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1442+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13851443
);
13861444
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.example-tvOSTests";
13871445
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1407,6 +1465,7 @@
14071465
LIBRARY_SEARCH_PATHS = (
14081466
"$(inherited)",
14091467
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1468+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
14101469
);
14111470
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.example-tvOSTests";
14121471
PRODUCT_NAME = "$(TARGET_NAME)";

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dependencies": {
99
"react": "^16.3.0-alpha.1",
1010
"react-native": "0.54.2",
11-
"react-native-dynamic-bundle": "git+https://github.com/mauritsd/react-native-dynamic-bundle"
11+
"react-native-dynamic-bundle": "git+https://github.com/mauritsd/react-native-dynamic-bundle",
12+
"react-native-fs": "^2.9.11"
1213
},
1314
"devDependencies": {
1415
"babel-preset-react-native": "4.0.0"

0 commit comments

Comments
 (0)