是否有可能在反应原生导航器中更改转换?

eya*_*l83 10 react-native

我有3个不同的反应原生组件,我使用导航器在它们之间导航.在我的第一个视图中,我定义了导航器:

查看1

<Navigator
    ref="nav"
    renderScene={@renderScene}
    initialRoute={@renderContent(I18n.t("Incidents"))}
    configureScene={ ->
      transition = Navigator.SceneConfigs.HorizontalSwipeJump
      transition.gestures = null
      transition
    }
  />
Run Code Online (Sandbox Code Playgroud)

如您所见,转换是Horizo​​ntalSwipeJump.

查看2

 @props.navigator.push
  component: IncidentScreen
  incidentId: incident.id
  sceneConfig: -> Navigator.SceneConfigs.FloatFromBottomAndroid
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在尝试使用FloatFromBottomAndroid进入视图#3,但是,它无法正常工作.

通过查看RN的源代码,我可以看到navigator.push方法从props获取动画:

var nextAnimationConfigStack = activeAnimationConfigStack.concat([
  this.props.configureScene(route),
]);
Run Code Online (Sandbox Code Playgroud)

那我该怎么办?

非常感谢.

Kev*_* Qi 13

你必须在这里挖掘一下反应原生来源的SceneConfigs列表,但是这里是写作时的当前列表:

PushFromRight
FloatFromRight
FloatFromLeft
FloatFromBottom
FloatFromBottomAndroid
FadeAndroid
HorizontalSwipeJump
HorizontalSwipeJumpFromRight
VerticalUpSwipeJump
VerticalDownSwipeJump
Run Code Online (Sandbox Code Playgroud)

用法示例:

<Navigator
  configureScene={(route) => {
    if (someCondition) {
      return Navigator.SceneConfigs.HorizontalSwipeJump;
    } else {
      return Navigator.SceneConfigs.PushFromRight;
    }
  }}
/>
Run Code Online (Sandbox Code Playgroud)


eya*_*l83 7

好的,我明白了.我在视图1中遗漏了这一部分:

configureScene={ (route) ->
      if route.sceneConfig
        route.sceneConfig
      else
        transition = Navigator.SceneConfigs.HorizontalSwipeJump
        transition.gestures = null
        transition
    }
Run Code Online (Sandbox Code Playgroud)