#javascript #android #react-native #splash-screen
Вопрос:
Я сталкиваюсь с проблемой, Когда я запускаю приложение, у меня белый экран остается на 2 секунды перед моей заставкой, Как решить эту проблему, я использую собственную версию 61, мне нужно удалить этот белый экран, который появляется перед моей заставкой, Он появляется всего на 2 секунды, но мне нужно удалить его, я искал и попробовал это сделать.,
<item name="android:windowDisablePreview">true</item>
в Android, но это не решает проблему
вот мой код «инициализатор приложения»
import React from 'react';
import {Alert} from 'react-native';
import AppNavigator from './router';
import SplashScreen from './SplashScreen';
import {InitializApp} from './actions/SettingsActions';
import {connect} from 'react-redux';
import NavigationService from './util/NavigationService';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {fcmService} from './util/FCMService';
class AppInitializer extends React.Component {
constructor(props) {
super(props);
}
async componentDidMount() {
/*************************************
* Push Notification
*************************************/
fcmService.requestPermission();
await fcmService.registerAppWithFCM();
await fcmService.register(
onRegister,
onNotification, // inapp notification
onOpenNotification, // fron notification center
);
async function onRegister(token) {
const oldDeviceToken = await AsyncStorage.getItem('deviceToken');
if (oldDeviceToken != token) {
await AsyncStorage.setItem('deviceToken', token);
// await AsyncStorage.setItem('oldDeviceToken', oldDeviceToken);
}
}
function onNotification(notify, data) {
console.log('onNotification', notify);
console.log('onNotification', data);
let buttons = [];
if (data.hasOwnProperty('type') amp;amp; data.type == 'category') {
buttons[0] = {
text: 'إلغاء',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
};
buttons[1] = {
text: 'اذهب للقسم',
onPress: () => {
NavigationService.navigate('categorydetails', {
category_id: data.id,
});
},
};
} else if (data.hasOwnProperty('type') amp;amp; data.type == 'product') {
buttons[0] = {
text: 'إلغاء',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
};
buttons[1] = {
text: 'اذهب للمنتج',
onPress: () => {
NavigationService.navigate('productdetails', {
product_id: data.id,
});
},
};
} else {
buttons[0] = {
text: 'موافق',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
};
}
Alert.alert(notify.title, notify.body, buttons, {cancelable: true});
}
function onOpenNotification(notify, data) {
console.log('onOpenNotification', data);
if (data.hasOwnProperty('type') amp;amp; data.type == 'category') {
NavigationService.navigate('categorydetails', {
category_id: data.id,
});
} else if (data.hasOwnProperty('type') amp;amp; data.type == 'product') {
NavigationService.navigate('productdetails', {
product_id: data.id,
});
} else {
Alert.alert(
notify.title,
notify.body,
[
{
text: 'موافق',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
],
{cancelable: true},
);
}
}
/*************************************
* Push Notification
*************************************/
this.props.InitializApp();
}
render() {
if (this.props.Loaded) {
return (
<AppNavigator
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
);
} else return <SplashScreen />;
}
}
const mapStateToProps = state => ({Loaded: state.settings.Loaded});
const mapDispatchToProps = dispatch => ({
InitializApp: () => dispatch(InitializApp()),
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(AppInitializer);
Ответ №1:
вам нужно выполнить этот процесс, пока заставка видна пользователю прямо сейчас, рендеринг ничего не сможет отобразить, поэтому вы не получите ничего, кроме белого экрана…
пожалуйста, используйте эту настройку «npm i react-родной-заставка-сохранить» правильно, затем проверьте еще раз…