Skip to content

Commit 9a2ca4b

Browse files
authored
feat: Example application in Expo
Fixes #21
1 parent a7c7c4c commit 9a2ca4b

37 files changed

+8272
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Handful of utilities you should keep in your toolbelt to handle offline/online c
88
## Important (Please read)
99
**This is the documentation for version 4.x.x. If you are migrating from v3 to v4, check the [release notes](https://github.com/rgommezz/react-native-offline/releases/tag/v4.0.0).**
1010

11+
## Example app
12+
A comprehensive [example app](/example) is available within Expo to play with the library and better understand its different modules. [Go and check it out!](https://expo.io/@rgommezz/example)
13+
1114
## Contents
1215

1316
* [Motivation](#motivation)

example/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p12
6+
*.key
7+
*.mobileprovision

example/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

example/App.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
3+
import { AppLoading, Font, Icon } from 'expo';
4+
import AppNavigator from './navigation/AppNavigator';
5+
import DummyNetworkContext from './DummyNetworkContext';
6+
7+
const onlineUrl = 'https://www.google.com/';
8+
const offlineUrl = 'https://www.weifhweopfhwioehfiwoephfpweoifhewifhpewoif.com';
9+
10+
export default class App extends React.Component {
11+
constructor(props) {
12+
super(props);
13+
this.state = {
14+
isLoadingComplete: false,
15+
network: {
16+
pingUrl: onlineUrl,
17+
toggleConnection: this.toggleConnection,
18+
},
19+
};
20+
}
21+
22+
toggleConnection = () => {
23+
this.setState(prevState => ({
24+
network: {
25+
...prevState.network,
26+
pingUrl:
27+
prevState.network.pingUrl === onlineUrl ? offlineUrl : onlineUrl,
28+
},
29+
}));
30+
};
31+
32+
loadResourcesAsync = async () =>
33+
Font.loadAsync({
34+
...Icon.Ionicons.font,
35+
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
36+
});
37+
38+
handleFinishLoading = () => {
39+
this.setState({ isLoadingComplete: true });
40+
};
41+
42+
render() {
43+
const { isLoadingComplete, network } = this.state;
44+
const { skipLoadingScreen } = this.props;
45+
if (!isLoadingComplete && !skipLoadingScreen) {
46+
return (
47+
<AppLoading
48+
startAsync={this.loadResourcesAsync}
49+
onFinish={this.handleFinishLoading}
50+
/>
51+
);
52+
}
53+
return (
54+
<DummyNetworkContext.Provider value={network}>
55+
<View style={styles.container}>
56+
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
57+
<AppNavigator />
58+
</View>
59+
</DummyNetworkContext.Provider>
60+
);
61+
}
62+
}
63+
64+
const styles = StyleSheet.create({
65+
container: {
66+
flex: 1,
67+
backgroundColor: '#fff',
68+
},
69+
});

example/DummyNetworkContext.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
3+
const DummyNetworkContext = React.createContext();
4+
export default DummyNetworkContext;

example/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Example app
2+
3+
This application showcases component utilities, redux, sagas integration and the offline queue with different configurations. You can try it out in Expo by using [this link](https://expo.io/@rgommezz/example).
4+
5+
### Runing it locally
6+
You need to have `expo-cli` installed.
7+
8+
```bash
9+
cd example
10+
yarn install
11+
expo start
12+
```
13+
14+
### Snapshots
15+
<div>
16+
<img align="left" src="https://user-images.githubusercontent.com/4982414/52172165-f3605b00-2761-11e9-87f3-bca71b0d3918.png" width="400">
17+
18+
<img align="right" src="https://user-images.githubusercontent.com/4982414/52172166-f52a1e80-2761-11e9-8d9b-aa5a7caa24e2.png" width="400">
19+
</div>

example/__tests__/App-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import App from '../App';
4+
import renderer from 'react-test-renderer';
5+
import NavigationTestUtils from 'react-navigation/NavigationTestUtils';
6+
7+
describe('App snapshot', () => {
8+
jest.useFakeTimers();
9+
beforeEach(() => {
10+
NavigationTestUtils.resetInternalState();
11+
});
12+
13+
it('renders the loading screen', async () => {
14+
const tree = renderer.create(<App />).toJSON();
15+
expect(tree).toMatchSnapshot();
16+
});
17+
18+
it('renders the root without loading screen', async () => {
19+
const tree = renderer.create(<App skipLoadingScreen />).toJSON();
20+
expect(tree).toMatchSnapshot();
21+
});
22+
});

example/app.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"expo": {
3+
"name": "example",
4+
"slug": "example",
5+
"privacy": "public",
6+
"sdkVersion": "32.0.0",
7+
"platforms": [
8+
"ios",
9+
"android"
10+
],
11+
"version": "1.0.0",
12+
"orientation": "portrait",
13+
"icon": "./assets/images/icon.png",
14+
"splash": {
15+
"image": "./assets/images/splash.png",
16+
"resizeMode": "contain",
17+
"backgroundColor": "#ffffff"
18+
},
19+
"updates": {
20+
"fallbackToCacheTimeout": 0
21+
},
22+
"assetBundlePatterns": [
23+
"**/*"
24+
],
25+
"ios": {
26+
"supportsTablet": true
27+
}
28+
}
29+
}
91.1 KB
Binary file not shown.

example/assets/images/icon.png

2.91 KB
Loading

0 commit comments

Comments
 (0)