Guest User

Untitled

a guest
Mar 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function fixNavigator(Navigator: *) {
  2. return (...args: any[]) => {
  3. class FixedNavigator extends Navigator(...args) {
  4. _blockDispatch: boolean;
  5.  
  6. constructor(...constructorArgs: any[]) {
  7. super(...constructorArgs);
  8.  
  9. const originalDispatch = this.dispatch;
  10.  
  11. this.dispatch = (...dispatchArgs): boolean => {
  12. // console.log('Dispatch', ...dispatchArgs);
  13.  
  14. let handled = false;
  15. const { type, routeName, force } = dispatchArgs[0]; // get action
  16. if (
  17. (type !== 'Navigation/NAVIGATE' && type !== 'Navigation/BACK') ||
  18. (type === 'Navigation/NAVIGATE' &&
  19. (routeName === 'DrawerClose' ||
  20. routeName === 'DrawerOpen' ||
  21. routeName === 'DrawerToggle')) ||
  22. force === true
  23. ) {
  24. // Non Navigate/Back action or Drawer action should dispatch right away
  25. handled = originalDispatch(...dispatchArgs);
  26. } else if (!this._blockDispatch) {
  27. this._blockDispatch = true;
  28. handled = originalDispatch(...dispatchArgs);
  29. InteractionManager.runAfterInteractions(() => {
  30. this._blockDispatch = false; // release after animation ended
  31. });
  32. } else {
  33.  
  34. handled = true;
  35. }
  36. return handled;
  37. };
  38. }
  39. }
  40.  
  41. return FixedNavigator;
  42. };
  43. }
  44.  
  45. const MainNavigator = fixNavigator(StackNavigator)({
  46. //kode lo di sini
  47. })
Add Comment
Please, Sign In to add comment