···11+import {useState} from 'react'
22+import {View} from 'react-native'
33+import {PrivacySensitive} from 'expo-privacy-sensitive'
44+55+import {useAppState} from '#/lib/hooks/useAppState'
66+import {isIOS} from '#/platform/detection'
77+import {atoms as a, useTheme} from '#/alf'
88+import {sizes as iconSizes} from '#/components/icons/common'
99+import {Mark as Logo} from '#/components/icons/Logo'
1010+1111+const ICON_SIZE = 'xl' as const
1212+1313+export function GrowthHack({
1414+ children,
1515+ align = 'right',
1616+}: {
1717+ children: React.ReactNode
1818+ align?: 'left' | 'right'
1919+}) {
2020+ const t = useTheme()
2121+2222+ // the button has a variable width and is absolutely positioned, so we need to manually
2323+ // set the minimum width of the underlying button
2424+ const [width, setWidth] = useState<number | undefined>(undefined)
2525+2626+ const appState = useAppState()
2727+2828+ if (!isIOS || appState !== 'active') return children
2929+3030+ return (
3131+ <View
3232+ style={[
3333+ a.relative,
3434+ a.justify_center,
3535+ align === 'right' ? a.align_end : a.align_start,
3636+ width === undefined ? {opacity: 0} : {minWidth: width},
3737+ ]}>
3838+ <PrivacySensitive
3939+ style={[
4040+ a.absolute,
4141+ a.z_10,
4242+ a.flex_col,
4343+ align === 'right'
4444+ ? [a.right_0, a.align_end]
4545+ : [a.left_0, a.align_start],
4646+ // when finding the size of the button, we need the containing
4747+ // element to have a concrete size otherwise the text will
4848+ // collapse to 0 width. so set it to a really big number
4949+ // and hide the entire thing (see above)
5050+ width === undefined && {width: 10000},
5151+ ]}>
5252+ <View
5353+ onLayout={evt => setWidth(evt.nativeEvent.layout.width)}
5454+ style={[
5555+ t.atoms.bg,
5656+ // make sure it covers the icon! the won't always be a button
5757+ {minWidth: iconSizes[ICON_SIZE], minHeight: iconSizes[ICON_SIZE]},
5858+ ]}>
5959+ {children}
6060+ </View>
6161+ </PrivacySensitive>
6262+ <Logo size={ICON_SIZE} />
6363+ </View>
6464+ )
6565+}