Hi,
How to use the example project using hooks? Is there a way to create services using functions or is it handled differently?
Can anyone help me to create a example folder using hooks and functions?
Thanks.
export default ExampleFunctional = props => {
const [registerToken, setRegisterToken] = useState()
const [fcmRegistered, setFcmRegistered] = useState()
const notif = useRef(new NotifService(
onRegister,
onNotif,
))
const onRegister = (token) => {
setRegisterToken(token.token)
setFcmRegistered(true)
}
const onNotif = (notif) => {
Alert.alert(notif.title, notif.message);
}
const handlePerm = (perms) => {
Alert.alert('Permissions', JSON.stringify(perms));
}
return (
<View style={styles.container}>
<Text style={styles.title}>
Example app react-native-push-notification
</Text>
<View style={styles.spacer}></View>
<TextInput
style={styles.textField}
value={registerToken}
placeholder="Register token"
/>
<View style={styles.spacer}></View>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.requestPermissions();
}}>
<Text>Ask for permission</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.localNotif();
}}>
<Text>Local Notification (now)</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.localNotif('sample.mp3');
}}>
<Text>Local Notification with sound (now)</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.scheduleNotif();
}}>
<Text>Schedule Notification in 30s</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.scheduleNotif('sample.mp3');
}}>
<Text>Schedule Notification with sound in 30s</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.cancelNotif();
}}>
<Text>Cancel last notification (if any)</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.cancelAll();
}}>
<Text>Cancel all notifications</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.checkPermission(handlePerm);
}}>
<Text>Check Permission</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.requestPermissions();
}}>
<Text>Request Permissions</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notif.current.abandonPermissions();
}}>
<Text>Abandon Permissions</Text>
</TouchableOpacity>
<View style={styles.spacer}></View>
{fcmRegistered && <Text>FCM Configured !</Text>}
<View style={styles.spacer}></View>
</View>
);
}
Most helpful comment