Skip to content

Commit 12d57b7

Browse files
committed
fixup! Refactor KavButton into SceneWrapper
1 parent d24c128 commit 12d57b7

File tree

4 files changed

+46
-56
lines changed

4 files changed

+46
-56
lines changed

src/components/common/SceneWrapper.tsx

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ interface SceneWrapperProps {
126126
// True to make the scene scrolling (if avoidKeyboard is false):
127127
scroll?: boolean
128128

129-
// Optional KeyboardAccessoryView rendered as a sibling to the SceneWrapper content:
130-
kavProps?: {
129+
// Optional "dock" view rendered at the bottom of the scene, attached to the
130+
// keyboard, tabs, footer, etc, whatever is highest:
131+
dockProps?: {
131132
children: React.ReactNode
132-
alwaysVisible?: boolean
133+
keyboardVisibleOnly?: boolean
133134
contentContainerStyle?: ViewStyle
134135
}
135136
}
@@ -162,7 +163,7 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
162163
padding = 0,
163164
renderFooter,
164165
scroll = false,
165-
kavProps
166+
dockProps
166167
} = props
167168

168169
const notificationHeight = useSelector(state => state.ui.notificationHeight)
@@ -179,47 +180,32 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
179180
}
180181
})
181182

182-
// Local keyboard visible state for KAV parity (iOS willShow vs Android didShow):
183-
const [isKeyboardVisibleFull, setKeyboardVisibleKav] = useState(false)
184-
useEffect(() => {
185-
const keyboardDidShowListener = Keyboard.addListener(
186-
isIos ? 'keyboardWillShow' : 'keyboardDidShow',
187-
() => {
188-
setKeyboardVisibleKav(true)
189-
}
190-
)
191-
const keyboardDidHideListener = Keyboard.addListener(
192-
isIos ? 'keyboardWillHide' : 'keyboardDidHide',
193-
() => {
194-
setKeyboardVisibleKav(false)
195-
}
196-
)
197-
return () => {
198-
keyboardDidShowListener.remove()
199-
keyboardDidHideListener.remove()
200-
}
201-
}, [isIos])
202-
183+
// Local keyboard opening/closing start/end state for dock parity between iOS
184+
// and Android. `keyboardWillShow`/`keyboardDidShow` mean different things on
185+
// each platform:
186+
const [isKeyboardVisibleDock, setKeyboardVisibleDock] = useState(false)
203187
// Track closing/opening state explicitly for animation direction:
204188
const isClosingSv = useSharedValue(false)
205189
useEffect(() => {
206-
const showListener = Keyboard.addListener(
207-
isIos ? 'keyboardWillShow' : 'keyboardDidShow',
208-
() => {
209-
isClosingSv.value = false
210-
}
211-
)
212-
const hideListener = Keyboard.addListener(
213-
isIos ? 'keyboardWillHide' : 'keyboardDidHide',
214-
() => {
215-
isClosingSv.value = true
216-
}
217-
)
190+
const showEvent = isIos ? 'keyboardWillShow' : 'keyboardDidShow'
191+
const hideEvent = isIos ? 'keyboardWillHide' : 'keyboardDidHide'
192+
const onShow = (): void => {
193+
setKeyboardVisibleDock(true)
194+
isClosingSv.value = false
195+
}
196+
const onHide = (): void => {
197+
setKeyboardVisibleDock(false)
198+
isClosingSv.value = true
199+
}
200+
const showListener = Keyboard.addListener(showEvent, onShow)
201+
const hideListener = Keyboard.addListener(hideEvent, onHide)
218202
return () => {
219203
showListener.remove()
220204
hideListener.remove()
221205
}
222-
}, [isIos, isClosingSv])
206+
// No need to depend on `isClosingSv` since it's a shared value
207+
// eslint-disable-next-line react-hooks/exhaustive-deps
208+
}, [isIos])
223209

224210
// Reset the footer ratio when focused
225211
// We can do this because multiple calls to resetFooterRatio isn't costly
@@ -341,9 +327,9 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
341327
return children
342328
}, [children, sceneWrapperInfo])
343329

344-
// Build Keyboard Accessory View element
345-
const alwaysVisibleKav = kavProps?.alwaysVisible === true
346-
const kavBaseStyle = useMemo(
330+
// Build Dock View element
331+
const keyboardVisibleOnlyDoc = dockProps?.keyboardVisibleOnly ?? true
332+
const dockBaseStyle = useMemo(
347333
() => ({
348334
position: 'absolute' as const,
349335
left: 0,
@@ -359,7 +345,7 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
359345
insetBottomSv.value = insets.bottom
360346
collapsedInsetSv.value = collapsedInsetBottom
361347
}, [collapsedInsetBottom, insets.bottom, collapsedInsetSv, insetBottomSv])
362-
const kavAnimatedStyle = useAnimatedStyle(() => {
348+
const dockAnimatedStyle = useAnimatedStyle(() => {
363349
// keyboardHeightDiff.value is negative when open; invert to get height
364350
const keyboardHeight =
365351
keyboardHeightDiff.value < 0 ? -keyboardHeightDiff.value : 0
@@ -379,13 +365,17 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
379365

380366
return { bottom }
381367
})
382-
const shouldShowKav =
383-
kavProps != null && (alwaysVisibleKav || isKeyboardVisibleFull)
384-
const kavElement = !shouldShowKav ? null : (
368+
const shouldShowDock =
369+
dockProps != null && (!keyboardVisibleOnlyDoc || isKeyboardVisibleDock)
370+
const dockElement = !shouldShowDock ? null : (
385371
<Reanimated.View
386-
style={[kavBaseStyle, kavAnimatedStyle, kavProps?.contentContainerStyle]}
372+
style={[
373+
dockBaseStyle,
374+
dockAnimatedStyle,
375+
dockProps?.contentContainerStyle
376+
]}
387377
>
388-
{kavProps?.children}
378+
{dockProps?.children}
389379
</Reanimated.View>
390380
)
391381

@@ -422,7 +412,7 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
422412
navigation={navigation}
423413
/>
424414
) : null}
425-
{kavElement}
415+
{dockElement}
426416
<FloatingNavFixer navigation={navigation} />
427417
</>
428418
)
@@ -465,7 +455,7 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
465455
navigation={navigation}
466456
/>
467457
) : null}
468-
{kavElement}
458+
{dockElement}
469459
<FloatingNavFixer navigation={navigation} />
470460
</>
471461
)
@@ -501,7 +491,7 @@ function SceneWrapperComponent(props: SceneWrapperProps): React.ReactElement {
501491
navigation={navigation}
502492
/>
503493
) : null}
504-
{kavElement}
494+
{dockElement}
505495
<FloatingNavFixer navigation={navigation} />
506496
</>
507497
)

src/components/scenes/RampCreateScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
776776
<SceneWrapper
777777
scroll
778778
hasTabs
779-
kavProps={{
780-
alwaysVisible: true,
779+
dockProps={{
780+
keyboardVisibleOnly: false,
781781
children: (
782782
<KavButtons
783783
primary={{

src/components/scenes/RampKycFormScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ export const RampKycFormScene = React.memo((props: Props) => {
193193
scroll
194194
hasTabs
195195
avoidKeyboard
196-
kavProps={{
197-
alwaysVisible: true,
196+
dockProps={{
197+
keyboardVisibleOnly: false,
198198
children: (
199199
<KavButtons
200200
primary={{

src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ export const FiatPluginEnterAmountScene = React.memo((props: Props) => {
241241
keyboardShouldPersistTaps="handled"
242242
hasNotifications
243243
hasTabs
244-
kavProps={{
245-
alwaysVisible: true,
244+
dockProps={{
245+
keyboardVisibleOnly: false,
246246
children: (
247247
<KavButtons
248248
primary={{

0 commit comments

Comments
 (0)