Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
react-native-back-android
Advanced tools
A Higher-order Component for handling back button press on React Native Android
A Higher-order Component for handling back button press on React Native Android
npm install --save react-native-back-android
(Take Navigator as an example. Can be used in any scenario.)
import React, { Component } from 'react'
import { AppRegistry, Button, Text, View, Alert } from 'react-native'
import { StackNavigator } from 'react-navigation'
import backAndroid, {
hardwareBackPress,
exitApp
} from 'react-native-back-android'
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome'
}
// reserved function for handling hardware back press
handleHardwareBackPress = () => {
Alert.alert(
'Quiting',
'Want to quit?',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{ text: 'OK', onPress: () => exitApp() }
],
{ cancelable: false }
);
// return true to stop bubbling
return true
};
render () {
const { navigate } = this.props.navigation
return (
<View>
<Text>Hello, Chat App!</Text>
<Button onPress={() => navigate('Chat')} title='Chat with Lucy' />
</View>
)
}
}
class ChatScreen extends React.Component {
static navigationOptions = {
title: 'Chat with Lucy'
}
// reserved function for handling hardware back press
handleHardwareBackPress = () => {
const { goBack } = this.props.navigation
Alert.alert(
'Going Back',
'Want to go back?',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{ text: 'OK', onPress: () => goBack() }
],
{ cancelable: false }
);
// return true to stop bubbling
return true
};
render () {
return (
<View>
<Text>Chat with Lucy</Text>
</View>
)
}
}
const ReactNativeBackAndroidExample = StackNavigator({
Home: { screen: hardwareBackPress(HomeScreen) },
Chat: { screen: hardwareBackPress(ChatScreen) }
})
AppRegistry.registerComponent('ReactNativeBackAndroidExample', () =>
backAndroid(ReactNativeBackAndroidExample)
)
Stateless component
...
import { hardwareBackPress } from 'react-native-back-android';
const Stateless = ({ navigator }) => (
<View>
<Text>Stateless</Text>
<Button
title="stateless"
onPress={() => {
navigator.pop();
}}
/>
</View>
);
const handleBackButtonPress = ({ navigation }) => {
navigation.goBack();
return true;
};
const EnhancedStateless = hardwareBackPress(Stateless, handleBackButtonPress);
export default EnhancedStateless;
FAQs
A Higher-order Component for handling back button press on React Native Android
The npm package react-native-back-android receives a total of 0 weekly downloads. As such, react-native-back-android popularity was classified as not popular.
We found that react-native-back-android demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.