@@ -7,6 +7,13 @@ export interface MessageEvent {
77}
88
99const ReactNativeBrownfield = {
10+ /**
11+ * Pop to the native screen.
12+ * @param animated - Whether to animate the transition (iOS only).
13+ * @platform android, ios
14+ * @example
15+ * ReactNativeBrownfield.popToNative(true);
16+ */
1017 popToNative : ( animated ?: boolean ) : void => {
1118 if ( Platform . OS === 'ios' ) {
1219 ReactNativeBrownfieldModule . popToNative ( ! ! animated ) ;
@@ -17,6 +24,14 @@ const ReactNativeBrownfield = {
1724 }
1825 } ,
1926
27+ /**
28+ * Enable or disable the iOS native back gesture and Android hardware back button.
29+ * @note This method is available both on the New Architecture and the Old Architecture.
30+ * @param enabled - Whether to enable native back gesture and button.
31+ * @platform android, ios
32+ * @example
33+ * ReactNativeBrownfield.setNativeBackGestureAndButtonEnabled(true);
34+ */
2035 setNativeBackGestureAndButtonEnabled : ( enabled : boolean ) : void => {
2136 if ( Platform . OS === 'ios' ) {
2237 ReactNativeBrownfieldModule . setPopGestureRecognizerEnabled ( enabled ) ;
@@ -27,11 +42,34 @@ const ReactNativeBrownfield = {
2742 }
2843 } ,
2944
45+ /**
46+ * Send a JSON-serializable message to the native host application. This resembles the web `window.postMessage` API.
47+ * @note This method is available both on the New Architecture and the Old Architecture.
48+ * @note This method requires the `data` to be JSON-serializable. The method does not catch any serialization errors thrown
49+ * by the `JSON.stringify` function, this is the responsibility of the caller.
50+ * @param data - The data to send to the native host application.
51+ * @platform android, ios
52+ * @example
53+ * ReactNativeBrownfield.postMessage({ text: 'Hello from React Native!', id: 2 });
54+ */
3055 postMessage : ( data : unknown ) : void => {
3156 const serialized = JSON . stringify ( data ) ;
3257 ReactNativeBrownfieldModule . postMessage ( serialized ) ;
3358 } ,
3459
60+ /**
61+ * Subscribe to messages sent from the native host application. Returns a subscription object with a `remove()` method for cleanup.
62+ * @param callback - The callback to invoke when a message is received from the native host application.
63+ * @returns A subscription object with a `remove` method for cleanup.
64+ * @platform android, ios
65+ * @example
66+ * const subscription = ReactNativeBrownfield.onMessage((event: MessageEvent) => {
67+ * console.log('Received from native:', event.data);
68+ * });
69+ *
70+ * // Later, to unsubscribe:
71+ * subscription.remove();
72+ */
3573 onMessage : (
3674 callback : ( event : MessageEvent ) => void
3775 ) : { remove : ( ) => void } => {
0 commit comments