react-navigation 防止重复点击
替换addNavigationHelers.js
/* Helpers for navigation */
importNavigationActionsfrom'./NavigationActions';
importinvariantfrom'./utils/invariant';
exportdefaultfunction(navigation){
// 添加点击判断
letdebounce =true;
return{
...navigation,
goBack:key=>{
letactualizedKey = key;
if(key ===undefined&& navigation.state.key) {
invariant(
typeofnavigation.state.key ==='string',
'key should be a string'
);
actualizedKey = navigation.state.key;
}
returnnavigation.dispatch(
NavigationActions.back({key: actualizedKey })
);
},
navigate: (routeName: string,
params?: NavigationParams,
action?: NavigationAction,):boolean=>{
if(debounce) {
debounce =false;
navigation.dispatch(
NavigationActions.navigate({
routeName,
params,
action,
}),
);
setTimeout(
()=>{
debounce =true;
},
500,
);
returntrue;
}
returnfalse;
},
pop:(n, params) =>
navigation.dispatch(
NavigationActions.pop({ n,immediate: params && params.immediate })
),
popToTop:params=>
navigation.dispatch(
NavigationActions.popToTop({immediate: params && params.immediate })
),
/**
* For updating current route params. For example the nav bar title and
* buttons are based on the route params.
* This means `setParams` can be used to update nav bar for example.
*/
// setParams: params => {
// invariant(
// navigation.state.key && typeof navigation.state.key === 'string',
// 'setParams cannot be called by root navigator'
// );
// const key = navigation.state.key;
// return navigation.dispatch(NavigationActions.setParams({ params, key }));
// },
setParams: (params: NavigationParams):boolean=>
navigation.dispatch(
NavigationActions.setParams({
params,
key: navigation.state.key,
}),
),
getParam:(paramName, defaultValue) =>{
constparams = navigation.state.params;
if(params && paramNameinparams) {
returnparams[paramName];
}
returndefaultValue;
},
push:(routeName, params, action) =>
navigation.dispatch(
NavigationActions.push({ routeName, params, action })
),
replace:(routeName, params, action) =>
navigation.dispatch(
NavigationActions.replace({
routeName,
params,
action,
key: navigation.state.key,
})
),
};
}