88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
/**
|
||
* @format
|
||
*/
|
||
import React, { useEffect, useState } from 'react';
|
||
import {
|
||
AppRegistry,
|
||
I18nManager,
|
||
Text as RNText,
|
||
StatusBar,
|
||
BackHandler,
|
||
View,
|
||
ToastAndroid,
|
||
} from 'react-native';
|
||
import { name as appName } from './app.json';
|
||
import { App } from './src/App';
|
||
// redux
|
||
import { Provider as ReduxProvider } from 'react-redux';
|
||
import { ReduxStore } from './src/provider/store';
|
||
// core
|
||
import { usePermissionReadSMS, usePermissionReceiveSMS, usePermissionSendSMS } from './src/core/permission';
|
||
// material
|
||
import { Provider as PaperProvider, Button, Text } from 'react-native-paper';
|
||
import { Theme } from './src/core/theme';
|
||
|
||
RNText.defaultProps = RNText.defaultProps || {};
|
||
RNText.defaultProps.style = { fontFamily: 'font' };
|
||
|
||
import { NavigationContainer } from '@react-navigation/native';
|
||
|
||
const Index = () => {
|
||
I18nManager.forceRTL(true);
|
||
const [ready, setReady] = useState(false);
|
||
|
||
useEffect(() => {
|
||
console.log('Asking permissions');
|
||
ask();
|
||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, []);
|
||
|
||
const ask = () => {
|
||
usePermissionReadSMS()
|
||
.then((value) => {
|
||
if (value) return usePermissionSendSMS();
|
||
else kill();
|
||
})
|
||
.then((value) => {
|
||
if (value) return usePermissionReceiveSMS();
|
||
else kill();
|
||
})
|
||
.then((value) => {
|
||
if (value) setReady(true);
|
||
else kill();
|
||
});
|
||
};
|
||
|
||
const kill = () => {
|
||
console.error('index.js/kill');
|
||
BackHandler.exitApp();
|
||
ToastAndroid.show('دسترسی ها داده نشده است.', 3000);
|
||
};
|
||
|
||
const Waiting = () => (
|
||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', padding: 30 }}>
|
||
<Text style={{ fontSize: 20, textAlign: 'center' }}>در انتظار ارائه دادن دسترسی ها</Text>
|
||
<Text style={{ marginBottom: 30, textAlign: 'center' }}>
|
||
از طریق تنظیمات اندروید دسترسی پیامک را به این اپ ارائه دهید
|
||
</Text>
|
||
<Button onPress={ask} mode="contained">
|
||
درخواست دسترسی
|
||
</Button>
|
||
</View>
|
||
);
|
||
|
||
return (
|
||
<>
|
||
<StatusBar backgroundColor={Theme.colors.primary} />
|
||
<ReduxProvider store={ReduxStore}>
|
||
<NavigationContainer theme={Theme}>
|
||
<PaperProvider theme={Theme}>{ready ? <App /> : <Waiting />}</PaperProvider>
|
||
</NavigationContainer>
|
||
</ReduxProvider>
|
||
</>
|
||
);
|
||
};
|
||
|
||
AppRegistry.registerComponent(appName, () => Index);
|