Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions packages/core-mobile/app/new/common/components/ScrollScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEffectiveHeaderHeight } from 'common/hooks/useEffectiveHeaderHeight'
import { useFadingHeaderNavigation } from 'common/hooks/useFadingHeaderNavigation'
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'
import {
LayoutChangeEvent,
LayoutRectangle,
Platform,
StyleProp,
Expand Down Expand Up @@ -118,8 +119,7 @@ export const ScrollScreen = ({

const headerRef = useRef<View>(null)
const contentHeaderHeight = useSharedValue<number>(0)
const footerHeight = useSharedValue<number>(0)
const footerRef = useRef<View>(null)
const [footerMeasuredHeight, setFooterMeasuredHeight] = useState(0)

const { onScroll, scrollY, targetHiddenProgress } = useFadingHeaderNavigation(
{
Expand Down Expand Up @@ -153,12 +153,9 @@ export const ScrollScreen = ({
})
}, [contentHeaderHeight])

useLayoutEffect(() => {
// eslint-disable-next-line max-params
footerRef?.current?.measure((x, y, width, height) => {
footerHeight.value = height
})
}, [footerHeight])
const onFooterLayout = useCallback((event: LayoutChangeEvent) => {
setFooterMeasuredHeight(event.nativeEvent.layout.height)
}, [])

const animatedBorderStyle = useAnimatedStyle(() => {
const opacity = interpolate(scrollY.value, [0, headerHeight], [0, 1])
Expand Down Expand Up @@ -224,26 +221,8 @@ export const ScrollScreen = ({
if (renderFooter) {
const footer = renderFooter()
if (footer) {
if (shouldAvoidKeyboard) {
return (
<KeyboardStickyView
enabled={!disableStickyFooter}
offset={{
opened: insets.bottom
}}>
<LinearGradientBottomWrapper>
<Animated.View
style={{
paddingHorizontal: 16,
paddingBottom: insets.bottom + 16
}}>
{footer}
</Animated.View>
</LinearGradientBottomWrapper>
</KeyboardStickyView>
)
} else {
return (
const footerInner = (
<View onLayout={onFooterLayout}>
<LinearGradientBottomWrapper>
<Animated.View
style={{
Expand All @@ -253,13 +232,33 @@ export const ScrollScreen = ({
{footer}
</Animated.View>
</LinearGradientBottomWrapper>
</View>
)

if (shouldAvoidKeyboard) {
return (
<KeyboardStickyView
enabled={!disableStickyFooter}
offset={{
opened: insets.bottom
}}>
{footerInner}
</KeyboardStickyView>
)
}

return footerInner
}
}

return null
}, [renderFooter, shouldAvoidKeyboard, disableStickyFooter, insets.bottom])
}, [
renderFooter,
shouldAvoidKeyboard,
disableStickyFooter,
insets.bottom,
onFooterLayout
])

const renderGrabber = useCallback(() => {
if (isModal)
Expand Down Expand Up @@ -321,7 +320,7 @@ export const ScrollScreen = ({
<KeyboardScrollView
testID={testID}
extraKeyboardSpace={
disableStickyFooter ? -footerHeight.value - insets.bottom : 0
disableStickyFooter ? -footerMeasuredHeight - insets.bottom : 0
}
keyboardDismissMode="interactive"
keyboardShouldPersistTaps="handled"
Expand All @@ -335,7 +334,7 @@ export const ScrollScreen = ({
{
paddingBottom: disableStickyFooter
? insets.bottom + 24
: footerHeight.value + 16,
: footerMeasuredHeight + 16,
paddingTop: headerHeight
}
]}
Expand Down Expand Up @@ -366,7 +365,9 @@ export const ScrollScreen = ({
contentContainerStyle={[
props?.contentContainerStyle,
{
paddingBottom: 32,
paddingBottom: renderFooter
? footerMeasuredHeight + 16
: insets.bottom + 24,
paddingTop: headerHeight
}
]}
Expand Down
Loading