From 1ff4daee12fe7e463381ad742ab6f651537e05e1 Mon Sep 17 00:00:00 2001 From: Abel Toledano Date: Thu, 28 Nov 2024 16:36:33 +0100 Subject: [PATCH] WEB-2109 remove onNativeEvent --- README.md | 28 --------------------- index.ts | 1 - src/__tests__/post-message-test.ts | 40 ------------------------------ src/post-message.ts | 21 ---------------- 4 files changed, 90 deletions(-) diff --git a/README.md b/README.md index 1d2ff57..d0462ba 100644 --- a/README.md +++ b/README.md @@ -634,34 +634,6 @@ Report a given feature status reportStatus: ({feature: 'ACCOUNT', status: 'CRITICAL' | 'GOOD' | 'BAD', reason: string}) => Promise; ``` -### onNativeEvent - -App version >=11.3 - -Listens to native app events - -```ts -type NativeEventHandler = ({ event }: {event: string}) => {action: 'default'}; - -onNativeEvent: (handler: NativeEventHandler) => () => void; -``` - -#### Example - -```ts -onNativeEvent(({event}) => { - if (event === 'tappedNavigationBarBackButton') { - // do something - } - return {action: 'default'}; -}); -``` - -#### Available events - -- `tappedNavigationBarBackButton`: fired when the user taps on the back button - of the native Navigation Bar. Allowed response actions: `default` - ### checkPermissionStatus App version >=11.4 diff --git a/index.ts b/index.ts index c81f7c5..6b127ab 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,5 @@ export { isWebViewBridgeAvailable, - onNativeEvent, NativeEventHandler, setLogger, } from './src/post-message'; diff --git a/src/__tests__/post-message-test.ts b/src/__tests__/post-message-test.ts index c8d1d59..b605bd2 100644 --- a/src/__tests__/post-message-test.ts +++ b/src/__tests__/post-message-test.ts @@ -2,8 +2,6 @@ import '../post-message'; import { isWebViewBridgeAvailable, postMessageToNativeApp, - onNativeEvent, - NativeEventHandler, } from '../post-message'; import { createFakeAndroidPostMessage, @@ -136,41 +134,3 @@ test('malformed json throws', () => { window.__tuenti_webview_bridge!.postMessage('{bad;json}'); }).toThrow(); }); - -test('onNativeEvent subscription', () => { - const ANY_ID = '123'; - const ANY_EVENT_NAME = 'any-event-name'; - - const request = { - type: 'NATIVE_EVENT', - id: ANY_ID, - payload: {event: ANY_EVENT_NAME}, - }; - - const expectedResponse = { - type: 'NATIVE_EVENT', - id: ANY_ID, - payload: {action: 'default'}, - }; - - createFakeWebKitPostMessage({ - checkMessage: (msg) => { - expect(msg).toMatchObject(expectedResponse); - }, - }); - - const handler = jest.fn(({event}) => { - expect(event).toBe(ANY_EVENT_NAME); - return {action: 'default'}; - }) as NativeEventHandler; - - const unsubscribe = onNativeEvent(handler); - - window.__tuenti_webview_bridge!.postMessage(JSON.stringify(request)); - - unsubscribe(); - - window.__tuenti_webview_bridge!.postMessage(JSON.stringify(request)); - - expect(handler).toHaveBeenCalledTimes(1); -}); diff --git a/src/post-message.ts b/src/post-message.ts index 88c4570..0efc5bd 100644 --- a/src/post-message.ts +++ b/src/post-message.ts @@ -6,11 +6,6 @@ import {getId} from './message-id'; * - ResponsesFromNativeApp: native app responds to a request initiated by the web */ type RequestsFromNativeApp = { - NATIVE_EVENT: { - type: 'NATIVE_EVENT'; - id: string; - payload: {event: string}; - }; SESSION_RENEWED: { type: 'SESSION_RENEWED'; id: string; @@ -598,22 +593,6 @@ export const listenToNativeMessage = ( }; }; -export const onNativeEvent = ( - eventHandler: NativeEventHandler, -): (() => void) => { - const handler = (payload: NativeAppRequestPayload<'NATIVE_EVENT'>) => { - const response = eventHandler({ - event: payload.event, - }); - - return { - action: response.action || 'default', - }; - }; - - return listenToNativeMessage('NATIVE_EVENT', handler); -}; - export const onSessionRenewal = ( handler: (payload: {accessToken: string}) => void, ): (() => void) => listenToNativeMessage('SESSION_RENEWED', handler);