-
Notifications
You must be signed in to change notification settings - Fork 583
/
Copy pathAnimatableHeader.tsx
72 lines (66 loc) · 2.12 KB
/
AnimatableHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { ArrowLeftIcon, Flex, useTheme, Text } from "@artsy/palette-mobile"
import { FadeInLeft } from "app/utils/animations/FadeInLeft"
import { useEffect } from "react"
import { TouchableOpacity, View } from "react-native"
import { useAnimatableHeaderContext } from "./AnimatableHeaderContext"
export interface AnimatableHeaderProps {
title: string
rightButtonDisabled?: boolean
rightButtonText?: string
onLeftButtonPress: () => void
onRightButtonPress?: () => void
}
export const AnimatableHeader = (props: AnimatableHeaderProps) => {
const { title, rightButtonDisabled, rightButtonText, onRightButtonPress } = props
const { space } = useTheme()
const { headerHeight, setTitle, titleShown } = useAnimatableHeaderContext()
useEffect(() => {
setTitle(title)
}, [title])
return (
<View
style={{
flexDirection: "row",
paddingHorizontal: space(2),
alignItems: "center",
height: headerHeight,
backgroundColor: "white",
}}
>
<TouchableOpacity
hitSlop={{ top: space(1), bottom: space(1), left: space(1), right: space(1) }}
onPress={props.onLeftButtonPress}
accessibilityLabel="Header back button"
>
<ArrowLeftIcon fill="black100" mt="2px" />
</TouchableOpacity>
<Flex
flex={1}
height={headerHeight}
justifyContent="center"
ml={`${space(0.5) + space(1)}px`}
>
<FadeInLeft show={titleShown}>
<Text testID="animated-header-title" variant="sm" numberOfLines={2}>
{title}
</Text>
</FadeInLeft>
</Flex>
{!!onRightButtonPress && !!rightButtonText && (
<TouchableOpacity
hitSlop={{ top: space(1), bottom: space(1), left: space(1), right: space(1) }}
onPress={onRightButtonPress}
disabled={rightButtonDisabled}
>
<Text
variant="sm"
style={{ textDecorationLine: "underline" }}
color={rightButtonDisabled ? "black30" : "black100"}
>
{rightButtonText}
</Text>
</TouchableOpacity>
)}
</View>
)
}