1.0.6 • Published 4 years ago

react-native-backstage v1.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Getting started

Install react-native-backstage using npm.

npm install react-native-backstage
// or 
yarn add react-native-backstage

Examples

The source code for the example (showcase) app is under the Example/ directory. If you want to play with the API but don't feel like trying it on a real app, you can run the example project. Clone the repo, go to the Example/ folder and run:

yarn install

Running on Android

Run the react native's cli command:

react-native run-android
import React, { useEffect, useState } from 'react';
import { Text, View, StyleSheet, BackHandler } from 'react-native';

import Backstage from 'react-native-backstage';

const App = () => {
	useEffect(() => {
		BackHandler.addEventListener('hardwareBackPress', onBackPress);
		return () => {
			BackHandler.removeEventListener('hardwareBackPress', onBackPress);
		};
	}, []);

	const onBackPress = () => {
		// 通过 moveTaskToBack() 使app退出到后台
		Backstage.moveTaskToBack((e) => {
			// 返回是否退出成功
			console.log(e);
		});
		return false;
	};

	const [ num, useNum ] = useState('11111');

	return (
		<View style={styles.container}>
			<Text
				onPress={() => {
					useNum('99999');
				}}
			>
				点击此处,再按下安卓返回{num}
			</Text>
		</View>
	);
};

export default App;

const styles = StyleSheet.create({
	container: {
		flex: 1,
		justifyContent: 'center',
		alignItems: 'center'
	}
});

License

么有

Credits

么得