react-native-device-clock-format
v0.1.3
Published
Determine whether the device is set to 12 or 24 hour time.
Downloads
5
Readme
react-native-device-clock-format
Determine whether the device is set to 12 or 24 hour time.
Add it to your project
- Run
npm install react-native-device-clock-format --save
- Open your project in XCode, right click on
Libraries
and clickAdd Files to "Your Project Name"
- Add
libDeviceClockFormat.a
toBuild Phases -> Link Binary With Libraries
. - Whenever you want to use it within React code now you can:
var DeviceClockFormat = require('react-native-device-clock-format');
Example
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
} = React;
var DeviceClockFormat = require('react-native-device-clock-format');
var SampleApp = React.createClass({
getInitialState() {
return { format: 'Unknown..' }
},
componentWillMount() {
this.fetchTimeFormat();
},
fetchTimeFormat() {
DeviceClockFormat.fetch((twelveHour, twentyFourHour) => {
if (twelveHour) {
this.setState({format: '12 hour'});
} else {
this.setState({format: '24 hour'});
}
});
},
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
{this.state.format}
</Text>
<TouchableOpacity onPress={this.fetchTimeFormat}>
<Text style={styles.instructions}>
Update time format
</Text>
</TouchableOpacity>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('SampleApp', () => SampleApp);