用newone替换堆栈中的最后一个场景?就像用动画推动新场景一样,当推动动画结束时,老一样从堆栈默默地加入。 NavigationExperimental StateUtils replaceAt和replaceAtIndex仅在没有动画的情况下更改顶部的场景。
答案 0 :(得分:1)
NavigationStateUtils
中没有为您执行此操作的实用程序功能,但您需要做的是push
,然后在导航过渡动画的最后,您执行reset
除了最新路线之外的所有路线。
由于您正在使用NavigationCardStack
,因此您必须使用InteractionManager
对reset
推送的组件NavigationCardStack
does not have a callback prop to call when the transition is finished进行has a onTransitionEnd
callback prop。< / p>
以下是一个例子:
// Navigation reducer
function routeReducer(
navigationState = {
routes: [],
index: 0,
},
action,
) {
switch (action.type) {
case 'replaceWithPushAnimation':
// Pass a `reset` flag to your component so it knows to `resetWithoutRoute`
return NavigationStateUtils.push(navigationState, action.route);
case 'resetWithoutRoute':
return NavigationStateUtils.reset(
navigationState,
[
// Copy of all the routes except for navigationState.routes[length - 2]
]);
default:
return navigationState;
}
}
// The component that you pushed
class PushedComponent extends React.Component {
componentDidMount() {
if (this.props.shouldResetWithoutPrevious) {
// This runs after the navigation transition is over
InteractionManager.runAfterInteractions(() => {
// This function calls the reducer to trigger the
// routes reset
this.props.onNavigate({
type: 'resetWithoutRoute',
});
});
}
}
// render() {}
}
如果您不喜欢这种方法,可以使用NavigationTransitioner
reset
来class MyCell: UITableViewCell {
@IBOutlet var myView: UIView!
@IBOutlet var myViewHeightConstraint: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
print(myView.bounds.height)
myView.layer.cornerRadius = myViewHeightConstraint.constant / 2
myView.layer.masksToBounds = true
}
}
进行reloadData
,因为它是一个较低级别的API ,你必须自己实现导航过渡。