App.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
import {View, TextInput, StyleSheet, NativeModules} from 'react-native'; | |
import SharedGroupPreferences from 'react-native-shared-group-preferences'; | |
const group = 'group.asap'; | |
const SharedStorage = NativeModules.SharedStorage; | |
const App = () => { | |
const [text, setText] = useState(''); | |
const widgetData = { | |
text, | |
}; | |
const handleSubmit = async () => { | |
try { | |
// iOS | |
await SharedGroupPreferences.setItem('widgetKey', widgetData, group); | |
} catch (error) { | |
console.log({error}); | |
} | |
// Android | |
SharedStorage.set(JSON.stringify({text})); | |
}; | |
return ( | |
<View style={styles.container}> | |
<TextInput | |
style={styles.input} | |
onChangeText={newText => setText(newText)} | |
value={text} | |
returnKeyType="send" | |
onEndEditing={handleSubmit} | |
placeholder="Enter the text to display..." | |
/> | |
</View> | |
); | |
}; | |
export default App; | |
const styles = StyleSheet.create({ | |
container: { | |
marginTop: '50%', | |
paddingHorizontal: 24, | |
}, | |
input: { | |
width: '100%', | |
borderBottomWidth: 1, | |
fontSize: 20, | |
minHeight: 40, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment