@react-navigation/native 8.0.0-alpha.32 → 8.0.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/android/build.gradle +4 -6
  2. package/assets/fonts/MaterialSymbolsOutlined.codepoints +179 -24
  3. package/assets/fonts/MaterialSymbolsOutlined_100.ttf +0 -0
  4. package/assets/fonts/MaterialSymbolsOutlined_200.ttf +0 -0
  5. package/assets/fonts/MaterialSymbolsOutlined_300.ttf +0 -0
  6. package/assets/fonts/MaterialSymbolsOutlined_400.ttf +0 -0
  7. package/assets/fonts/MaterialSymbolsOutlined_500.ttf +0 -0
  8. package/assets/fonts/MaterialSymbolsOutlined_600.ttf +0 -0
  9. package/assets/fonts/MaterialSymbolsOutlined_700.ttf +0 -0
  10. package/assets/fonts/MaterialSymbolsRounded.codepoints +179 -24
  11. package/assets/fonts/MaterialSymbolsRounded_100.ttf +0 -0
  12. package/assets/fonts/MaterialSymbolsRounded_200.ttf +0 -0
  13. package/assets/fonts/MaterialSymbolsRounded_300.ttf +0 -0
  14. package/assets/fonts/MaterialSymbolsRounded_400.ttf +0 -0
  15. package/assets/fonts/MaterialSymbolsRounded_500.ttf +0 -0
  16. package/assets/fonts/MaterialSymbolsRounded_600.ttf +0 -0
  17. package/assets/fonts/MaterialSymbolsRounded_700.ttf +0 -0
  18. package/assets/fonts/MaterialSymbolsSharp.codepoints +179 -24
  19. package/assets/fonts/MaterialSymbolsSharp_100.ttf +0 -0
  20. package/assets/fonts/MaterialSymbolsSharp_200.ttf +0 -0
  21. package/assets/fonts/MaterialSymbolsSharp_300.ttf +0 -0
  22. package/assets/fonts/MaterialSymbolsSharp_400.ttf +0 -0
  23. package/assets/fonts/MaterialSymbolsSharp_500.ttf +0 -0
  24. package/assets/fonts/MaterialSymbolsSharp_600.ttf +0 -0
  25. package/assets/fonts/MaterialSymbolsSharp_700.ttf +0 -0
  26. package/lib/module/useLinking.js +52 -7
  27. package/lib/module/useLinking.js.map +1 -1
  28. package/lib/typescript/src/native/MaterialSymbolData.d.ts +1 -1
  29. package/lib/typescript/src/native/MaterialSymbolData.d.ts.map +1 -1
  30. package/lib/typescript/src/useLinkBuilder.d.ts +30 -30
  31. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -1
  32. package/lib/typescript/src/useLinking.d.ts.map +1 -1
  33. package/package.json +6 -6
  34. package/src/native/MaterialSymbolData.tsx +155 -0
  35. package/src/useLinking.tsx +67 -6
@@ -1,4 +1,5 @@
1
1
  import {
2
+ CommonActions,
2
3
  findFocusedRoute,
3
4
  getActionFromState as getActionFromStateDefault,
4
5
  getPathFromState as getPathFromStateDefault,
@@ -282,6 +283,66 @@ export function useLinking<ParamList extends ParamListBase>(
282
283
  previousIndexRef.current = index;
283
284
  pendingPopStatePathRef.current = path;
284
285
 
286
+ const rollbackHistory = () => {
287
+ const delta = previousIndex - index;
288
+
289
+ if (delta === 0) {
290
+ return;
291
+ }
292
+
293
+ pendingPopStatePathRef.current = undefined;
294
+
295
+ // eslint-disable-next-line promise/always-return
296
+ history.go(delta)?.then(() => {
297
+ previousIndexRef.current = history.index;
298
+ });
299
+ };
300
+
301
+ const rollbackHistoryIfPrevented = (callback: () => void) => {
302
+ let removePrevented = false;
303
+ let actionChangedState = false;
304
+
305
+ const unsubscribeEvent = navigation.addListener(
306
+ '__unsafe_event__',
307
+ (e) => {
308
+ if (e.data.type === 'beforeRemove' && e.data.defaultPrevented) {
309
+ removePrevented = true;
310
+ }
311
+ }
312
+ );
313
+
314
+ // After preventing remove, user may synchronously continue navigation
315
+ // This is common when showing a confirmation dialog
316
+ // If this action produces an update, we don't want to rollback the history
317
+ const unsubscribeAction = navigation.addListener(
318
+ '__unsafe_action__',
319
+ (e) => {
320
+ if (!e.data.noop) {
321
+ actionChangedState = true;
322
+ }
323
+ }
324
+ );
325
+
326
+ try {
327
+ callback();
328
+ } finally {
329
+ unsubscribeEvent();
330
+ unsubscribeAction();
331
+ }
332
+
333
+ if (removePrevented && !actionChangedState) {
334
+ rollbackHistory();
335
+ }
336
+ };
337
+
338
+ const dispatch = (action: Parameters<typeof navigation.dispatch>[0]) => {
339
+ rollbackHistoryIfPrevented(() => navigation.dispatch(action));
340
+ };
341
+
342
+ const resetRoot = (state: Parameters<typeof navigation.resetRoot>[0]) => {
343
+ rollbackHistoryIfPrevented(() => navigation.resetRoot(state));
344
+ };
345
+
285
346
  // When browser back/forward is clicked, we first need to check if state object for this index exists
286
347
  // If it does we'll reset to that state object
287
348
  // Otherwise, we'll handle it like a regular deep link
@@ -304,9 +365,9 @@ export function useLinking<ParamList extends ParamListBase>(
304
365
  // If we detect that the state change is popping the last entry
305
366
  // Dispatch a back action instead of resetting to the state
306
367
  // This makes sure changes to history state since the entry was added don't get lost
307
- navigation.goBack();
368
+ dispatch(CommonActions.goBack());
308
369
  } else {
309
- navigation.resetRoot(record.state);
370
+ resetRoot(record.state);
310
371
  }
311
372
 
312
373
  return;
@@ -343,7 +404,7 @@ export function useLinking<ParamList extends ParamListBase>(
343
404
 
344
405
  if (action !== undefined) {
345
406
  try {
346
- navigation.dispatch(action);
407
+ dispatch(action);
347
408
  } catch (e) {
348
409
  // Ignore any errors from deep linking.
349
410
  // This could happen in case of malformed links, navigation object not being initialized etc.
@@ -356,14 +417,14 @@ export function useLinking<ParamList extends ParamListBase>(
356
417
  );
357
418
  }
358
419
  } else {
359
- navigation.resetRoot(state);
420
+ resetRoot(state);
360
421
  }
361
422
  } else {
362
- navigation.resetRoot(state);
423
+ resetRoot(state);
363
424
  }
364
425
  } else {
365
426
  // if current path didn't return any state, we should revert to initial state
366
- navigation.resetRoot(state);
427
+ resetRoot(state);
367
428
  }
368
429
  });
369
430
  }, [enabled, history, ref, validateRoutesNotExistInRootState]);