@@ -6,8 +6,18 @@ import type { ViewProps } from 'react-native';
66import { Iterable } from '../../core/classes/Iterable' ;
77import { EmbeddedSessionContext } from '../context/EmbeddedSessionContext' ;
88
9- interface EmbeddedSessionManagerProps extends ViewProps {
9+ export interface EmbeddedSessionManagerProps extends ViewProps {
1010 children ?: ReactNode ;
11+ /**
12+ * Is the current screen in focus?
13+ *
14+ * When `false`, this wrapper does not start an embedded session (e.g. host
15+ * screen not focused). Defaults to `true`.
16+ *
17+ * This is not necessary to use. It is only useful if you want to avoid
18+ * starting the session when the screen is hidden but still technically there.
19+ */
20+ isActive ?: boolean ;
1121}
1222
1323/**
@@ -17,12 +27,13 @@ interface EmbeddedSessionManagerProps extends ViewProps {
1727 */
1828export const EmbeddedSessionManager = ( {
1929 children,
30+ isActive = true ,
2031 ...viewProps
2132} : EmbeddedSessionManagerProps ) => {
2233 const hasActiveParentSession = useContext ( EmbeddedSessionContext ) ;
2334
2435 useEffect ( ( ) => {
25- if ( hasActiveParentSession ) {
36+ if ( hasActiveParentSession || ! isActive ) {
2637 return ;
2738 }
2839
@@ -31,7 +42,7 @@ export const EmbeddedSessionManager = ({
3142 return ( ) => {
3243 Iterable . embeddedManager . endSession ( ) ;
3344 } ;
34- } , [ hasActiveParentSession ] ) ;
45+ } , [ hasActiveParentSession , isActive ] ) ;
3546
3647 return (
3748 < EmbeddedSessionContext . Provider value = { true } >
0 commit comments