diff --git a/apps/AndroidApp/app/src/main/AndroidManifest.xml b/apps/AndroidApp/app/src/main/AndroidManifest.xml
index b7c0735e8..c6f1665df 100644
--- a/apps/AndroidApp/app/src/main/AndroidManifest.xml
+++ b/apps/AndroidApp/app/src/main/AndroidManifest.xml
@@ -18,6 +18,10 @@
android:name=".ReferralsActivity"
android:exported="false"
android:theme="@style/Theme.AndroidBrownfieldApp" />
+
promise.resolve(true) }
- .setNegativeButton("Cancel") { _, _ -> promise.resolve(false) }
- .setCancelable(false)
- .show()
- }
- }
-
- override fun showNativeBanner(message: String, onDismiss: Callback) {
- runOnUiThread {
- AlertDialog.Builder(this)
- .setMessage(message)
- .setPositiveButton("Dismiss") { _, _ -> onDismiss.invoke() }
- .setCancelable(false)
- .show()
- }
- }
}
@Composable
@@ -177,20 +119,28 @@ private fun MainScreen(modifier: Modifier = Modifier) {
name = ReactNativeConstants.APP_NAME,
)
+ EspressoTagAnchor(tag = E2eTestIds.nativeAppOpenReactNative) {
+ Button(
+ onClick = {
+ activity?.let {
+ it.startActivity(
+ Intent(it, ReactNativeActivity::class.java)
+ // Forward the Detox flag so the RN host keeps E2E behaviour.
+ .putExtra("DetoxE2E", it.intent?.getStringExtra("DetoxE2E"))
+ )
+ }
+ }
+ ) {
+ Text("Open React Native")
+ }
+ }
+
PostMessageCard(
onMessageReceived = { message -> postMessageToastText = message },
textInputEnabled = !isDetoxE2E,
)
- Spacer(modifier = Modifier.height(1.dp))
-
- ReactNativeView(
- modifier = Modifier
- .fillMaxWidth()
- .height(520.dp)
- .clip(RoundedCornerShape(16.dp))
- .background(MaterialTheme.colorScheme.surface)
- )
+ Spacer(modifier = Modifier.height(16.dp))
}
postMessageToastText?.let { message ->
@@ -202,58 +152,6 @@ private fun MainScreen(modifier: Modifier = Modifier) {
}
}
-@Composable
-fun ReactNativeView(
- modifier: Modifier = Modifier
-) {
- val activity = LocalContext.current as? Activity
- val brownfieldE2E = remember(activity) {
- activity?.intent?.getStringExtra("DetoxE2E") == "YES"
- }
-
- AndroidFragment(
- modifier = modifier,
- arguments = Bundle().apply {
- putString(
- ReactNativeFragmentArgNames.ARG_MODULE_NAME,
- ReactNativeConstants.MAIN_MODULE_NAME
- )
- putBoolean(
- ReactNativeFragmentArgNames.ARG_WAIT_FOR_FULL_DISPLAY,
- ReactNativeConstants.WAIT_FOR_FULL_DISPLAY
- )
- putBoolean(
- ReactNativeFragmentArgNames.ARG_COLLECT_THREAD_METRICS,
- true
- )
- putBundle(
- ReactNativeFragmentArgNames.ARG_LAUNCH_OPTIONS,
- Bundle().apply {
- putString(
- "nativeOsVersionLabel",
- "Android ${Build.VERSION.RELEASE}"
- )
- putBoolean("brownfieldE2E", brownfieldE2E)
- }
- )
- },
- onUpdate = { fragment ->
- fragment.onMetrics = OnDisplayMetrics(BrownfieldMetricsLogger::logDisplay)
- }
- )
-}
-
-private class ReactNativeFragmentFactory : FragmentFactory() {
- override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
- if (className == ReactNativeFragment::class.java.name) {
- return ReactNativeFragment().apply {
- onMetrics = OnDisplayMetrics(BrownfieldMetricsLogger::logDisplay)
- }
- }
- return super.instantiate(classLoader, className)
- }
-}
-
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
diff --git a/apps/AndroidApp/app/src/main/java/com/callstack/brownfield/android/example/ReactNativeActivity.kt b/apps/AndroidApp/app/src/main/java/com/callstack/brownfield/android/example/ReactNativeActivity.kt
new file mode 100644
index 000000000..d942ef86b
--- /dev/null
+++ b/apps/AndroidApp/app/src/main/java/com/callstack/brownfield/android/example/ReactNativeActivity.kt
@@ -0,0 +1,171 @@
+package com.callstack.brownfield.android.example
+
+import android.app.Activity
+import android.content.Intent
+import android.content.res.Configuration
+import android.os.Build
+import android.os.Bundle
+import androidx.activity.compose.setContent
+import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.navigationBarsPadding
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.semantics.testTagsAsResourceId
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentFactory
+import androidx.fragment.compose.AndroidFragment
+import com.callstack.brownfield.android.example.ui.theme.AndroidBrownfieldAppTheme
+import com.callstack.nativebrownfieldnavigation.BrownfieldNavigationDelegate
+import com.callstack.nativebrownfieldnavigation.BrownfieldNavigationManager
+import com.callstack.nativebrownfieldnavigation.UserType
+import com.callstack.reactnativebrownfield.OnDisplayMetrics
+import com.callstack.reactnativebrownfield.ReactNativeFragment
+import com.callstack.reactnativebrownfield.constants.ReactNativeFragmentArgNames
+import com.facebook.react.bridge.Callback
+import com.facebook.react.bridge.Promise
+
+/**
+ * Full-screen React Native host, pushed from [MainActivity] (mirrors RNAppScreen on iOS).
+ * Each launch creates a new fragment, so every presentation gets its own display metrics.
+ */
+class ReactNativeActivity : AppCompatActivity(), BrownfieldNavigationDelegate {
+ private val isDetoxE2E: Boolean
+ get() = intent?.getStringExtra("DetoxE2E") == "YES"
+
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+
+ ReactNativeHostManager.onConfigurationChanged(application, newConfig)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ // Own Brownfield navigation only while this activity is foregrounded.
+ BrownfieldNavigationManager.setDelegate(this)
+ if (isDetoxE2E) {
+ window.decorView.post { window.decorView.requestFocus() }
+ }
+ }
+
+ override fun onPause() {
+ // Release ownership before another host can become the active delegate.
+ BrownfieldNavigationManager.clearDelegate()
+ super.onPause()
+ }
+
+ override fun onWindowFocusChanged(hasFocus: Boolean) {
+ super.onWindowFocusChanged(hasFocus)
+ if (!hasFocus && isDetoxE2E) {
+ window.decorView.post { window.decorView.requestFocus() }
+ }
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ supportFragmentManager.fragmentFactory = ReactNativeFragmentFactory()
+ super.onCreate(null)
+ enableEdgeToEdge()
+
+ setContent {
+ AndroidBrownfieldAppTheme {
+ ReactNativeView(
+ modifier = Modifier
+ .fillMaxSize()
+ .navigationBarsPadding()
+ .semantics { testTagsAsResourceId = true }
+ )
+ }
+ }
+ }
+
+ override fun navigateToSettings(user: UserType) {
+ startActivity(Intent(this, SettingsActivity::class.java))
+ }
+
+ override fun navigateToReferrals(userId: String) {
+ startActivity(
+ Intent(this, ReferralsActivity::class.java).putExtra(
+ ReferralsActivity.EXTRA_USER_ID,
+ userId
+ )
+ )
+ }
+
+ override fun requestNativeConfirmation(title: String, promise: Promise) {
+ runOnUiThread {
+ AlertDialog.Builder(this)
+ .setTitle(title)
+ .setPositiveButton("OK") { _, _ -> promise.resolve(true) }
+ .setNegativeButton("Cancel") { _, _ -> promise.resolve(false) }
+ .setCancelable(false)
+ .show()
+ }
+ }
+
+ override fun showNativeBanner(message: String, onDismiss: Callback) {
+ runOnUiThread {
+ AlertDialog.Builder(this)
+ .setMessage(message)
+ .setPositiveButton("Dismiss") { _, _ -> onDismiss.invoke() }
+ .setCancelable(false)
+ .show()
+ }
+ }
+}
+
+@Composable
+private fun ReactNativeView(
+ modifier: Modifier = Modifier
+) {
+ val activity = LocalContext.current as? Activity
+ val brownfieldE2E = remember(activity) {
+ activity?.intent?.getStringExtra("DetoxE2E") == "YES"
+ }
+
+ AndroidFragment(
+ modifier = modifier,
+ arguments = Bundle().apply {
+ putString(
+ ReactNativeFragmentArgNames.ARG_MODULE_NAME,
+ ReactNativeConstants.MAIN_MODULE_NAME
+ )
+ putBoolean(
+ ReactNativeFragmentArgNames.ARG_WAIT_FOR_FULL_DISPLAY,
+ ReactNativeConstants.WAIT_FOR_FULL_DISPLAY
+ )
+ putBoolean(
+ ReactNativeFragmentArgNames.ARG_COLLECT_THREAD_METRICS,
+ true
+ )
+ putBundle(
+ ReactNativeFragmentArgNames.ARG_LAUNCH_OPTIONS,
+ Bundle().apply {
+ putString(
+ "nativeOsVersionLabel",
+ "Android ${Build.VERSION.RELEASE}"
+ )
+ putBoolean("brownfieldE2E", brownfieldE2E)
+ }
+ )
+ },
+ onUpdate = { fragment ->
+ fragment.onMetrics = OnDisplayMetrics(BrownfieldMetricsLogger::logDisplay)
+ }
+ )
+}
+
+private class ReactNativeFragmentFactory : FragmentFactory() {
+ override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
+ if (className == ReactNativeFragment::class.java.name) {
+ return ReactNativeFragment().apply {
+ onMetrics = OnDisplayMetrics(BrownfieldMetricsLogger::logDisplay)
+ }
+ }
+ return super.instantiate(classLoader, className)
+ }
+}
diff --git a/apps/AppleApp/Brownfield Apple App/E2eTestIds.swift b/apps/AppleApp/Brownfield Apple App/E2eTestIds.swift
index c4fe83d8b..bcccc7f2b 100644
--- a/apps/AppleApp/Brownfield Apple App/E2eTestIds.swift
+++ b/apps/AppleApp/Brownfield Apple App/E2eTestIds.swift
@@ -3,6 +3,7 @@ import Foundation
/// Keep in sync with `@callstack/brownfield-example-shared-tests` `e2eTestIds`.
enum E2eTestIds {
static let appleAppGreeting = "brownfield-e2e-appleapp-greeting"
+ static let appleAppOpenReactNative = "brownfield-e2e-appleapp-open-react-native"
static let appleAppPostMessageSend = "brownfield-e2e-appleapp-post-message-send"
static let appleAppPostMessageToast = "brownfield-e2e-appleapp-post-message-toast"
static let appleAppNativeSettings = "brownfield-e2e-appleapp-native-settings"
diff --git a/apps/AppleApp/Brownfield Apple App/components/ContentView.swift b/apps/AppleApp/Brownfield Apple App/components/ContentView.swift
index c9cdefb14..4ab83153c 100644
--- a/apps/AppleApp/Brownfield Apple App/components/ContentView.swift
+++ b/apps/AppleApp/Brownfield Apple App/components/ContentView.swift
@@ -35,8 +35,9 @@ struct ContentView: View {
@State private var postMessageToastText = ""
var body: some View {
- NavigationView {
- ZStack {
+ // Toast sits above NavigationView so RN postMessage stays visible on the pushed RN screen.
+ ZStack {
+ NavigationView {
ScrollView {
VStack(spacing: 16) {
GreetingCard(name: hostAppName)
@@ -45,19 +46,20 @@ struct ContentView: View {
Text("Open React Native")
}
.buttonStyle(.borderedProminent)
+ .accessibilityIdentifier(E2eTestIds.appleAppOpenReactNative)
MessagesView()
}
.frame(maxWidth: .infinity)
.padding(16)
}
+ }
- if showPostMessageToast {
- Toast(
- message: postMessageToastText,
- isShowing: $showPostMessageToast
- )
- }
+ if showPostMessageToast {
+ Toast(
+ message: postMessageToastText,
+ isShowing: $showPostMessageToast
+ )
}
}
.onAppear {
diff --git a/apps/ExpoApp56/RNApp.tsx b/apps/ExpoApp56/RNApp.tsx
index 559c3afc0..505052d58 100644
--- a/apps/ExpoApp56/RNApp.tsx
+++ b/apps/ExpoApp56/RNApp.tsx
@@ -4,12 +4,19 @@ import BrownfieldNavigation from '@callstack/brownfield-navigation';
import { checkAndFetchUpdate } from './src/utils/expo-rn-updates';
import Counter from './src/components/counter';
+import { useMarkFullyDisplayed } from './src/hooks/use-mark-fully-displayed';
type RNAppProps = {
nativeOsVersionLabel?: string;
+ brownfieldPresentationID?: string;
};
-export default function RNApp({ nativeOsVersionLabel }: RNAppProps) {
+export default function RNApp({
+ nativeOsVersionLabel,
+ brownfieldPresentationID,
+}: RNAppProps) {
+ useMarkFullyDisplayed(brownfieldPresentationID);
+
const requestNativeConfirmation = async () => {
try {
await BrownfieldNavigation.requestNativeConfirmation(
@@ -57,15 +64,12 @@ export default function RNApp({ nativeOsVersionLabel }: RNAppProps) {
title="Navigate to Referrals"
onPress={() => BrownfieldNavigation.navigateToReferrals('123')}
/>
-
-
+
diff --git a/apps/ExpoApp56/entry.tsx b/apps/ExpoApp56/entry.tsx
index efb445d65..0fedc055a 100644
--- a/apps/ExpoApp56/entry.tsx
+++ b/apps/ExpoApp56/entry.tsx
@@ -7,8 +7,13 @@ import {
} from '@callstack/brownfield-example-shared-tests/runtime';
import RNApp from './RNApp';
+import { useMarkFullyDisplayed } from './src/hooks/use-mark-fully-displayed';
+
+function App(
+ props: BrownfieldRootProps & { brownfieldPresentationID?: string }
+) {
+ useMarkFullyDisplayed(props.brownfieldPresentationID);
-function App(props: BrownfieldRootProps) {
useEffect(() => {
syncBrownfieldE2EModeFromRootProps(props.brownfieldE2E);
return () => syncBrownfieldE2EModeFromRootProps(undefined);
diff --git a/apps/ExpoApp56/jest.setup.js b/apps/ExpoApp56/jest.setup.js
index 14d2c2591..bdb396836 100644
--- a/apps/ExpoApp56/jest.setup.js
+++ b/apps/ExpoApp56/jest.setup.js
@@ -1 +1,7 @@
require('@callstack/brownfield-example-shared-tests/jest/setup');
+
+// postMessage tab reads safe-area insets; tests render it without a SafeAreaProvider.
+jest.mock(
+ 'react-native-safe-area-context',
+ () => require('react-native-safe-area-context/jest/mock').default
+);
diff --git a/apps/ExpoApp56/src/app/postMessage.tsx b/apps/ExpoApp56/src/app/postMessage.tsx
index 815dd098a..3c4caf62d 100644
--- a/apps/ExpoApp56/src/app/postMessage.tsx
+++ b/apps/ExpoApp56/src/app/postMessage.tsx
@@ -4,13 +4,16 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { brownfieldE2ETestIds } from '@callstack/brownfield-example-shared-tests/e2eTestIds';
import ReactNativeBrownfield from '@callstack/react-native-brownfield';
import type { MessageEvent } from '@callstack/react-native-brownfield';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ThemedView } from '@/components/themed-view';
import { ThemedText } from '@/components/themed-text';
import type { Message } from '@/components/postMessage/Message';
import { MessageBubble } from '@/components/postMessage/MessageBubble';
+import { BottomTabInset, Spacing } from '@/constants/theme';
export default function PostMessageTab() {
+ const insets = useSafeAreaInsets();
const [messages, setMessages] = useState([]);
const flatListRef = useRef>(null);
@@ -50,7 +53,17 @@ export default function PostMessageTab() {
}, []);
return (
-
+
{
+ if (!brownfieldPresentationID) {
+ return;
+ }
+ const timeout = setTimeout(
+ () => ReactNativeBrownfield.markFullyDisplayed(brownfieldPresentationID),
+ DEMO_FULL_DISPLAY_DELAY_MS
+ );
+ return () => clearTimeout(timeout);
+ }, [brownfieldPresentationID]);
+}
diff --git a/apps/ExpoApp57/RNApp.tsx b/apps/ExpoApp57/RNApp.tsx
index c48e82fba..0ae252320 100644
--- a/apps/ExpoApp57/RNApp.tsx
+++ b/apps/ExpoApp57/RNApp.tsx
@@ -5,22 +5,19 @@ import { checkAndFetchUpdate } from './src/utils/expo-rn-updates';
import Counter from './src/components/counter';
import ReactNativeBrownfield from '@callstack/react-native-brownfield';
-import { useEffect } from 'react';
+import { useMarkFullyDisplayed } from './src/hooks/use-mark-fully-displayed';
type RNAppProps = {
nativeOsVersionLabel?: string;
brownfieldPresentationID?: string;
};
-export default function RNApp({ nativeOsVersionLabel, brownfieldPresentationID }: RNAppProps) {
- useEffect(() => {
- if (brownfieldPresentationID) {
- setTimeout(() => {
- ReactNativeBrownfield.markFullyDisplayed(brownfieldPresentationID);
- }, 500);
- }
- }, [brownfieldPresentationID]);
-
+export default function RNApp({
+ nativeOsVersionLabel,
+ brownfieldPresentationID,
+}: RNAppProps) {
+ useMarkFullyDisplayed(brownfieldPresentationID);
+
const requestNativeConfirmation = async () => {
try {
await BrownfieldNavigation.requestNativeConfirmation(
@@ -68,18 +65,18 @@ export default function RNApp({ nativeOsVersionLabel, brownfieldPresentationID }
title="Navigate to Referrals"
onPress={() => BrownfieldNavigation.navigateToReferrals('123')}
/>
-
-
+
-