Skip to content

Commit

Permalink
Merge pull request #32 from rmrs/update_example_dependencies
Browse files Browse the repository at this point in the history
Update example dependencies
  • Loading branch information
erezrokah authored Aug 13, 2019
2 parents 7984942 + 015fab7 commit 37ad69d
Show file tree
Hide file tree
Showing 42 changed files with 5,161 additions and 3,933 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.validate.enable": false,
"javascript.validate.enable": false,
"editor.formatOnSave": true,
}
3 changes: 0 additions & 3 deletions example/.babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
59 changes: 44 additions & 15 deletions example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,37 @@
; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js
node_modules/react-native/Libraries/react-native/React.js

; Ignore polyfills
.*/Libraries/polyfills/.*
node_modules/react-native/Libraries/polyfills/.*

; Ignore metro
.*/node_modules/metro/.*
; These should not be required directly
; require from fbjs/lib instead: require('fbjs/lib/warning')
node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/HMRLoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

module.system=haste
module.system.haste.use_name_reducers=true
# get basename
Expand All @@ -44,27 +54,46 @@ module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/RNTester/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/IntegrationTests/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation.js
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
inexact-spread=warn
unnecessary-invariant=warn
signature-verification-failure=warn
deprecated-utility=error

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.78.0
^0.98.0
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ buck-out/

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
14 changes: 14 additions & 0 deletions example/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"useTabs": false,
"overrides": [
{
"files": "*.json",
"options": { "printWidth": 200 }
}
]
}
218 changes: 218 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/**
* @flow
* @format
*/
import React, { Component, Fragment } from 'react';
import {
StyleSheet,
Text,
View,
DeviceEventEmitter,
Button,
Dimensions,
Platform,
Alert,
} from 'react-native';
import RNSettings from 'react-native-settings';

type State = {
locationOn: boolean,
airplaneOn: boolean,
};

const Screen = {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
};

export default class example extends Component<void, State> {
state: State;

state = { locationOn: false, airplaneOn: false };

componentDidMount() {
RNSettings.getSetting(RNSettings.LOCATION_SETTING).then(result => {
if (result === RNSettings.ENABLED) {
this.setState({ locationOn: true });
} else {
this.setState({ locationOn: false });
}
});

if (Platform.OS === 'android') {
RNSettings.getSetting(RNSettings.AIRPLANE_MODE_SETTING).then(result => {
if (result === RNSettings.ENABLED) {
this.setState({ airplaneOn: true });
} else {
this.setState({ airplaneOn: false });
}
});

// Register to gps provider change event
DeviceEventEmitter.addListener(
RNSettings.GPS_PROVIDER_EVENT,
this.handleGPSProviderEvent,
);
// Register to airplane mode change event
DeviceEventEmitter.addListener(
RNSettings.AIRPLANE_MODE_EVENT,
this.handleAirplaneModeEvent,
);
}
}

handleGPSProviderEvent = (e: { [string]: string }) => {
if (e[RNSettings.LOCATION_SETTING] === RNSettings.ENABLED) {
this.setState({ locationOn: true });
} else {
this.setState({ locationOn: false });
}
};

handleAirplaneModeEvent = (e: { [string]: string }) => {
if (e[RNSettings.AIRPLANE_MODE_SETTING] === RNSettings.ENABLED) {
this.setState({ airplaneOn: true });
} else {
this.setState({ airplaneOn: false });
}
};

openLocationSetting = () => {
if (Platform.OS === 'ios') {
Alert.alert(
'Not supported!',
'Not supported on IOS just yet. Stay tuned ~_~',
);
return;
}
RNSettings.openSetting(RNSettings.ACTION_LOCATION_SOURCE_SETTINGS).then(
result => {
if (result === RNSettings.ENABLED) {
this.setState({ locationOn: true });
} else {
this.setState({ locationOn: false });
}
},
);
};

openAirplaneSetting = () => {
if (Platform.OS === 'ios') {
Alert.alert(
'Not supported!',
'Not supported on IOS just yet. Stay tuned ~_~',
);
return;
}
RNSettings.openSetting(RNSettings.ACTION_AIRPLANE_MODE_SETTINGS).then(
result => {
if (result === RNSettings.ENABLED) {
this.setState({ airplaneOn: true });
} else {
this.setState({ airplaneOn: false });
}
},
);
};

render() {
const asterisk =
Platform.OS === 'ios' ? (
<Text style={styles.notSupportedText}>
{' '}
* Not supported yet on iOS.
</Text>
) : (
<Text />
);

const { locationOn, airplaneOn } = this.state;

return (
<Fragment>
<View style={styles.container}>
<View style={styles.title}>
<Text style={styles.welcome}>react-native-settings</Text>
</View>
<SettingRow
name="Location"
on={locationOn}
onAvailable
onPress={this.openLocationSetting}
onPressAvailable={Platform.OS !== 'ios'}
/>
<SettingRow
name="Airplane Mode"
on={airplaneOn}
onAvailable={Platform.OS !== 'ios'}
onPress={this.openAirplaneSetting}
onPressAvailable={Platform.OS !== 'ios'}
/>
{asterisk}
</View>
</Fragment>
);
}
}

type SettingRowProps = {
name: string,
on: boolean,
onAvailable: boolean,
onPress: () => void,
onPressAvailable: boolean,
};

const SettingRow = ({
name,
onAvailable,
onPressAvailable,
onPress,
on,
}: SettingRowProps) => {
let status = <Text />;

if (onAvailable) {
status = on ? (
<Text style={styles.greenText}> ON</Text>
) : (
<Text style={styles.redText}> OFF</Text>
);
} else {
status = <Text style={styles.blackText}> N/A*</Text>;
}

return (
<View style={styles.settingRowContainer}>
<Text style={styles.text}>{name}:</Text>
{status}
<Button title={onPressAvailable ? 'Change' : 'N/A*'} onPress={onPress} />
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
settingRowContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: Screen.width / 1.5,
marginBottom: 20,
},
title: { marginTop: 20, marginBottom: 20 },
notSupportedText: { marginTop: 40 },
redText: { color: 'red', fontSize: 18 },
greenText: { color: 'green', fontSize: 18 },
blackText: { color: 'black', fontSize: 18 },
text: { fontSize: 18 },
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import Index from '../index.android.js';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
import App from '../App';

jest.mock('react-native-settings', () => {
return { getSetting: jest.fn(() => Promise.resolve()) };
});

it('renders correctly', () => {
const tree = renderer.create(
<Index />
);
renderer.create(<App />);
});
12 changes: 0 additions & 12 deletions example/__tests__/index.ios.js

This file was deleted.

Loading

0 comments on commit 37ad69d

Please sign in to comment.