при обработке уведомлений в корневом компоненте я хотел бы иметь возможность проверить, какой экран активен в данный момент, и перейти к конкретному экрану на основе данных уведомления. Я пробовал перемещаться по объекту Layout
, но не могу найти способ доступа к навигации.
Корневой компонент:
import React from 'react';
import {createRootNavigator} from './router';
import Expo , {Permissions, Notifications } from 'expo';
import {Alert, Platform} from 'react-native';
const Layout = createRootNavigator();
export default class App extends React.Component {
state = {
notification: {},
isSplashReady: false,
isAppReady: false,
};
componentDidMount() {
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
removeNotifications(){
if(Platform.OS === 'ios'){
Expo.Notifications.setBadgeNumberAsync(0);
}
else{
Expo.Notifications.dismissAllNotificationsAsync();
}
}
_handleNotification = (notification) => {
this.setState({notification: notification});
Alert.alert(
this.state.notification.data.title,
this.state.notification.data.body,
[
{text: 'Ok', onPress: () => this.removeNotifications(), style: 'cancel'},
],
{ cancelable: true }
)
};
render() {
return (
<Layout />
);
}
}