|
| 1 | +--- |
| 2 | +title: ImageHeader - 图片头部组件 |
| 3 | +nav: |
| 4 | + title: RN组件 |
| 5 | + path: /react-native |
| 6 | +group: |
| 7 | + title: Display |
| 8 | + path: /display |
| 9 | +--- |
| 10 | + |
| 11 | +# ImageHeader 图片头部组件 |
| 12 | + |
| 13 | +## 效果演示 |
| 14 | + |
| 15 | +### 1. 普通 ImageHeader |
| 16 | + |
| 17 | +```tsx | pure |
| 18 | +<ImageHeader headerBackgroundImg={require('../../assets/images/bg_rank.png')} headerHeight={px(161)} {...props}> |
| 19 | + <Flex justifyContent="center" backgroundColor="white" height={100}> |
| 20 | + <Text>111</Text> |
| 21 | + </Flex> |
| 22 | +</ImageHeader> |
| 23 | +``` |
| 24 | + |
| 25 | +<center> |
| 26 | + <figure> |
| 27 | + <img |
| 28 | + alt="header-ios1.png" |
| 29 | + src="https://td-dev-public.oss-cn-hangzhou.aliyuncs.com/maoyes-app/1609999430064140139.png" |
| 30 | + style="width: 375px; margin-right: 10px; border: 1px solid #ddd;" |
| 31 | + /> |
| 32 | + </figure> |
| 33 | +</center> |
| 34 | + |
| 35 | +### 2. ImageHeader 配置 left、right 和 headerLeftColor |
| 36 | + |
| 37 | +```tsx | pure |
| 38 | +<ImageHeader |
| 39 | + headerBackgroundImg={require('../../assets/images/bg_rank.png')} |
| 40 | + headerHeight={px(161)} |
| 41 | + headerLeftColor={theme.colors.white} |
| 42 | + headerLeft="返回" |
| 43 | + headerRight={<Icon name="delete" size={px(20)} color={theme.colors.white} />} |
| 44 | + {...props} |
| 45 | +> |
| 46 | + <Flex justifyContent="center" backgroundColor="white" height={100}> |
| 47 | + <Text>111</Text> |
| 48 | + </Flex> |
| 49 | +</ImageHeader> |
| 50 | +``` |
| 51 | + |
| 52 | +<center> |
| 53 | + <figure> |
| 54 | + <img |
| 55 | + alt="header-ios2.png" |
| 56 | + src="https://td-dev-public.oss-cn-hangzhou.aliyuncs.com/maoyes-app/1609999550703021067.png" |
| 57 | + style="width: 375px; margin-right: 10px; border: 1px solid #ddd;" |
| 58 | + /> |
| 59 | + </figure> |
| 60 | +</center> |
| 61 | + |
| 62 | +### 3. ImageHeader 配置 headerBackgroundColor |
| 63 | + |
| 64 | +```tsx | pure |
| 65 | +<ImageHeader |
| 66 | + headerBackgroundImg={require('../../assets/images/bg_rank.png')} |
| 67 | + headerHeight={px(161)} |
| 68 | + headerBackgroundColor={theme.colors.white} |
| 69 | + headerLeft="返回" |
| 70 | + headerRight={<Icon name="delete" size={px(20)} color={theme.colors.white} />} |
| 71 | + {...props} |
| 72 | +> |
| 73 | + <Flex justifyContent="center" height={100}> |
| 74 | + <Text>111</Text> |
| 75 | + </Flex> |
| 76 | +</ImageHeader> |
| 77 | +``` |
| 78 | + |
| 79 | +<center> |
| 80 | + <figure> |
| 81 | + <img |
| 82 | + alt="header-ios3.png" |
| 83 | + src="https://td-dev-public.oss-cn-hangzhou.aliyuncs.com/maoyes-app/1610000705310241428.png" |
| 84 | + style="width: 375px; margin-right: 10px; border: 1px solid #ddd;" |
| 85 | + /> |
| 86 | + </figure> |
| 87 | +</center> |
| 88 | + |
| 89 | +### 4. AnimatedHeader |
| 90 | + |
| 91 | +```tsx | pure |
| 92 | +import { useScrollHandler } from 'react-native-redash'; |
| 93 | +import Animated from 'react-native-reanimated'; |
| 94 | + |
| 95 | +export default () => { |
| 96 | + const { scrollHandler, y } = useScrollHandler(); |
| 97 | + |
| 98 | + return ( |
| 99 | + <AnimateHeader |
| 100 | + scrollY={y} |
| 101 | + scrollHeight={200} |
| 102 | + headerTitle="测试啊啊啊啊啊" |
| 103 | + headerLeft="返回" |
| 104 | + headerBackgroundColor={theme.colors.white} |
| 105 | + {...props} |
| 106 | + headerRight={ |
| 107 | + <TouchableOpacity activeOpacity={0.5} onPress={() => props.navigation.goBack()}> |
| 108 | + <Icon name="delete" size={px(20)} color={theme.colors.primaryColor} /> |
| 109 | + </TouchableOpacity> |
| 110 | + } |
| 111 | + /> |
| 112 | + <Animated.ScrollView {...scrollHandler}> |
| 113 | + <ImageHeader |
| 114 | + headerBackgroundImg={require('../../assets/images/bg_rank.png')} |
| 115 | + headerHeight={px(161)} |
| 116 | + headerLeftColor={theme.colors.white} |
| 117 | + headerRight={ |
| 118 | + <TouchableOpacity activeOpacity={0.5} onPress={() => props.navigation.goBack()}> |
| 119 | + <Icon name="delete" size={px(20)} color={theme.colors.primaryColor} /> |
| 120 | + </TouchableOpacity> |
| 121 | + } |
| 122 | + {...props} |
| 123 | + > |
| 124 | + <Flex justifyContent="center" height={100}> |
| 125 | + <Text>111</Text> |
| 126 | + </Flex> |
| 127 | + </ImageHeader> |
| 128 | + <Box width={200} height={900} /> |
| 129 | + </Animated.ScrollView> |
| 130 | + ) |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +<center> |
| 135 | + <figure> |
| 136 | + <img |
| 137 | + alt="header-ios4.gif" |
| 138 | + src="https://td-dev-public.oss-cn-hangzhou.aliyuncs.com/maoyes-app/1608877076955547998.gif" |
| 139 | + style="width: 375px; margin-right: 10px; border: 1px solid #ddd;" |
| 140 | + /> |
| 141 | + </figure> |
| 142 | +</center> |
| 143 | + |
| 144 | +## ImageHeader 组件 API |
| 145 | + |
| 146 | +| 属性 | 必填 | 说明 | 类型 | 默认值 | |
| 147 | +| --------------------- | ------- | -------------------- | --------------------- | --------------------------- | |
| 148 | +| headerTitle | `false` | 头部文字 | `ReactNode` | | |
| 149 | +| headerRight | `false` | 头部右侧内容 | `ReactNode` | | |
| 150 | +| headerLeft | `false` | 头部左侧内容 | `ReactNode` | | |
| 151 | +| headerLeftColor | `false` | 左侧返回键和字体颜色 | `string` | `theme.colors.primaryColor` | |
| 152 | +| headerBackgroundColor | `false` | 头部背景颜色 | `string` | `transparent` | |
| 153 | +| headerBackgroundImg | `true` | 头部背景图片 | `ImageSourcePropType` | | |
| 154 | +| headerHeight | `false` | 头部高度 | `number` | | |
| 155 | +| onPress | `false` | 左边图标点击事件 | `() => void` | | |
| 156 | +| showLeft | `false` | 是否显示左边图标 | `boolean` | `true` | |
| 157 | + |
| 158 | +## AnimateHeader 组件 API |
| 159 | + |
| 160 | +| 属性 | 必填 | 说明 | 类型 | 默认值 | |
| 161 | +| --- | --- | --- | --- | --- | |
| 162 | +| headerTitle | `true` | 头部文字 | `string` | | |
| 163 | +| headerTitleStyle | `false` | 头部文字样式 | `TextStyle` | | |
| 164 | +| scrollY | `false` | 滚动距离 | `Animated.SharedValue<number>` | `0` | |
| 165 | +| scrollHeight | `false` | 纵向滚动到哪个值时显示 `ImageHeader` | `number` | `300` | |
| 166 | +| headerHeight | `true` | 头部高度 | `number` | | |
| 167 | +| headerRight | `false` | 头部右侧内容 | `ReactNode` | | |
| 168 | +| headerLeft | `false` | 头部左侧内容 | `ReactNode` | | |
| 169 | +| headerLeftColor | `false` | 左侧返回键和字体颜色 | `string` | `theme.colors.primaryColor` | |
| 170 | +| headerBackgroundColor | `false` | 头部背景颜色 | `string` | `transparent` | |
| 171 | +| onPress | `false` | 左边按钮点击事件 | `() => void` | | |
| 172 | +| showLeft | `false` | 是否显示左边图标 | `boolean` | `true` | |
0 commit comments