Адаптивная навигация Deep Linking открывает приложение, но не корректирует страницу - PullRequest
1 голос
/ 28 сентября 2019

Проблема

Я пытаюсь настроить Deep Linking, и он не открывается на экране, указанном в моем URL.Приложение открывается, но всегда на текущем экране, а не на экране, указанном в URL.

Мое приложение имеет следующую структуру навигации, и я пытаюсь перейти к экрану уведомлений, когда приложение открывается

  1. Навигатор переключателя верхнего уровня
    1. Экран SplashScreen
    2. AuthLoading
    3. Приложение (BottomTabNavigator)
      1. Главная
      2. Профиль
      3. Уведомления
    4. Аут

Что я пробовал

Я попытался настроить новое приложение и следовать его документации , и оно правильно работает в новом проекте, но я не могу заставить его работать в моем текущем проекте.Я также включил избыточность в новый проект для тестирования той же среды.

Я тестирую, запустив xcrun simctl openurl booted esportsdeeplink://app/notifications для iOS и adb shell am start -W -a android.intent.action.VIEW -d “esportsdeeplink://app/notifications” com.benji.esportscompetition для Android.

Оба имеют одинаковый результат открытия приложения, но не переходят на указанную страницу

Enviornment

  • Reaction-native v0.60.4
  • реагировать-навигация v3.11.1
  • redux v4.0.4
  • реагировать-избыточен v7.1.0

код Я попытался включить весь соответствующий код, но сократил некоторые операции импорта и другой код, чтобы попытаться быть кратким.Я могу опубликовать любой дополнительный код, если он окажется вам полезным

Index.js (точка входа)

import App from './src/app/App';

const ReactNativeRedux = () => (
  <Provider store={store}>
    <PersistGate loading={<SplashScreen />} persistor={persistor}>
      <PushNotifications />
      <App />
    </PersistGate>
  </Provider>
);

AppRegistry.registerComponent(appName, () => ReactNativeRedux);

App.js

import AppContainer from './Components/BottomNavigation/NavigationRouting';

class App extends React.Component {
  render(props) {
    const prefix = 'esportsdeeplink://'
    console.log('prefix', prefix)
    return (
      <Fragment>
          <View style={{ flex: 1, backgroundColor }}>
          <StatusBar translucent backgroundColor="transparent" />
            <LoadingSpinner loading={this.props.loading} />
            <AppContainer
              ref={(navigatorRef) => {
                NavigationService.setTopLevelNavigator(navigatorRef);
              }}
              uriPrefix={prefix}
              screenProps={{
                http,
                saveFriendsFnUser: this.saveFriendsFnUser,
                signupComplete: this.signupComplete,
              }}
            />
          </View>
      </Fragment>
    );
  }
}

const mapStateToProps = (state) => ({
  loading: state.api.loading,
  user: state.user,
  math: state.math,
  response: state.response,
});

const mapDispatchToProps = (dispatch) => ({
  startupRequest: () => {
    dispatch(startupRequest());
  },
});

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(App);

NavigationRouting.js (где создаются мои навигаторы)

const BottomTabNav = createBottomTabNavigator(
  {
    Home: {
      screen: HomeScreen
    },
    Profile: {
      screen: ProfileStack
    },
    Notifications: {
      screen: Notifications,
      navigationOptions: () => ({
         tabBarVisible: false
       }),
      path: 'notifications',
    },

  },
  {
    tabBarComponent: CustomTabNav,
    initialRouteName: "Home"
  }
);

export default createAppContainer(
  createSwitchNavigator(
    {
      SplashScreen,
      AuthLoading: AuthLoadingScreen,
      App: {
        screen: BottomTabNav,
        path: 'app',
      },
      Auth: {
        screen: AuthStack,
        path: 'auth'
      }
    }
  )
);

Настройка Deep Linking

iOS

iOS setup

projectFolder / ios / eSportsCompetition / AppDelegate.m

#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

@end

Android

projectFolder / android / app / src / main / AndroidManifest.xml

 <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="esportsdeeplink" />
        </intent-filter>
      </activity>
...