@absolutejs/absolute 0.20.0-beta.57 → 0.20.0-beta.59

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.
@@ -826,6 +826,11 @@ const bridgeBootstrap = (path: string, safeAreaInsets: { bottom: number; left: n
826
826
  send({ format: 3, kind: 'event', event: 'navigation', path });
827
827
  }
828
828
  };
829
+ globalThis.__absoluteRequestBack = () => {
830
+ const event = new CustomEvent('absolute:back-request', { cancelable: true });
831
+ if (!dispatchEvent(event)) return;
832
+ send({ format: 3, kind: 'event', event: 'back-unhandled', path: currentPath });
833
+ };
829
834
  if (\${DEV_ORIGIN ? 'true' : 'false'}) {
830
835
  const publishPath = () => {
831
836
  const path = location.pathname + location.search + location.hash;
@@ -931,12 +936,12 @@ export function AbsoluteWebHost() {
931
936
  }, [safeAreaInsets.bottom, safeAreaInsets.left, safeAreaInsets.right, safeAreaInsets.top]);
932
937
  useEffect(() => {
933
938
  const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
934
- if (!canGoBack) return false;
935
- webView.current?.goBack();
939
+ if (!indexUri) return false;
940
+ webView.current?.injectJavaScript('globalThis.__absoluteRequestBack?.(); true;');
936
941
  return true;
937
942
  });
938
943
  return () => subscription.remove();
939
- }, [canGoBack]);
944
+ }, [indexUri]);
940
945
 
941
946
  const respond = (message: Record<string, unknown>) => {
942
947
  const source = JSON.stringify(message).replaceAll('\\u2028', '\\\\u2028').replaceAll('\\u2029', '\\\\u2029');
@@ -976,6 +981,11 @@ export function AbsoluteWebHost() {
976
981
  else activeWebPath.current = message.path;
977
982
  return;
978
983
  }
984
+ if (message.kind === 'event' && message.event === 'back-unhandled') {
985
+ if (canGoBack) webView.current?.goBack();
986
+ else BackHandler.exitApp();
987
+ return;
988
+ }
979
989
  if (message.kind !== 'request' || typeof message.id !== 'string' || message.path !== activeWebPath.current) return;
980
990
  try {
981
991
  if (typeof message.params !== 'object' || message.params === null || Array.isArray(message.params)) throw new Error('Expo bridge method params are invalid.');