|
| 1 | +import React from 'react'; |
| 2 | +import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native'; |
| 3 | +import type { Scenario } from '../../shared/helpers'; |
| 4 | +import { ScrollViewMarker } from 'react-native-screens/experimental'; |
| 5 | +import { TabsContainer } from '../../../shared/gamma/containers/tabs'; |
| 6 | +import { Rectangle } from '../../../shared/Rectangle'; |
| 7 | +import Colors from '../../../shared/styling/Colors'; |
| 8 | +import { generateNextColor } from '../../../shared/utils/color-generator'; |
| 9 | + |
| 10 | +const SCENARIO: Scenario = { |
| 11 | + name: 'Active marker for tabs', |
| 12 | + key: 'test-svm-active-scroll-view-for-tabs', |
| 13 | + details: |
| 14 | + 'Reproduces nested tab content where multiple descendant ScrollViews stay mounted under a non-scroll wrapper. ' + |
| 15 | + 'Switch pages with the buttons and verify that tab bar minimize behavior follows the active ScrollViewMarker ' + |
| 16 | + 'instead of remaining attached to the first registered ScrollView.', |
| 17 | + platforms: ['ios'], |
| 18 | + AppComponent: App, |
| 19 | +}; |
| 20 | + |
| 21 | +export default SCENARIO; |
| 22 | + |
| 23 | +const ITEM_COUNT = 24; |
| 24 | + |
| 25 | +function App() { |
| 26 | + return ( |
| 27 | + <TabsContainer |
| 28 | + routeConfigs={[ |
| 29 | + { |
| 30 | + name: 'Journal', |
| 31 | + Component: JournalLikeScreen, |
| 32 | + options: { |
| 33 | + title: 'Journal', |
| 34 | + ios: { |
| 35 | + icon: { type: 'sfSymbol', name: 'book.closed' }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + name: 'Other', |
| 41 | + Component: PlaceholderTab, |
| 42 | + options: { |
| 43 | + title: 'Other', |
| 44 | + ios: { |
| 45 | + icon: { type: 'sfSymbol', name: 'square.grid.2x2' }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + ]} |
| 50 | + ios={{ |
| 51 | + tabBarMinimizeBehavior: 'onScrollDown', |
| 52 | + }} |
| 53 | + /> |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +function JournalLikeScreen() { |
| 58 | + const [activePage, setActivePage] = React.useState(0); |
| 59 | + |
| 60 | + return ( |
| 61 | + <View style={styles.screen}> |
| 62 | + <View style={styles.header}> |
| 63 | + <Text style={styles.title}>Nested content with active marker</Text> |
| 64 | + <View style={styles.controls}> |
| 65 | + <PageButton |
| 66 | + label="Day 1" |
| 67 | + selected={activePage === 0} |
| 68 | + onPress={() => setActivePage(0)} |
| 69 | + /> |
| 70 | + <PageButton |
| 71 | + label="Day 2" |
| 72 | + selected={activePage === 1} |
| 73 | + onPress={() => setActivePage(1)} |
| 74 | + /> |
| 75 | + </View> |
| 76 | + </View> |
| 77 | + |
| 78 | + <View style={styles.pagerHost}> |
| 79 | + <Page |
| 80 | + active={activePage === 0} |
| 81 | + label="Day 1" |
| 82 | + accent={Colors.YellowLight100} |
| 83 | + /> |
| 84 | + <Page |
| 85 | + active={activePage === 1} |
| 86 | + label="Day 2" |
| 87 | + accent={Colors.GreenLight100} |
| 88 | + /> |
| 89 | + </View> |
| 90 | + </View> |
| 91 | + ); |
| 92 | +} |
| 93 | + |
| 94 | +function PlaceholderTab() { |
| 95 | + return ( |
| 96 | + <ScrollView contentContainerStyle={styles.placeholderScrollContent}> |
| 97 | + <Text style={styles.placeholderText}>Second tab placeholder</Text> |
| 98 | + {Array.from({ length: 20 }, (_, index) => ( |
| 99 | + <Rectangle |
| 100 | + key={index} |
| 101 | + color={generateNextColor()} |
| 102 | + width={'100%'} |
| 103 | + height={88} |
| 104 | + /> |
| 105 | + ))} |
| 106 | + </ScrollView> |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +function Page(props: { active: boolean; label: string; accent: string }) { |
| 111 | + const { active, label, accent } = props; |
| 112 | + |
| 113 | + return ( |
| 114 | + <View |
| 115 | + pointerEvents={active ? 'auto' : 'none'} |
| 116 | + style={[ |
| 117 | + styles.pageContainer, |
| 118 | + { opacity: active ? 1 : 0, zIndex: active ? 1 : 0 }, |
| 119 | + ]}> |
| 120 | + <ScrollViewMarker active={active} style={styles.fillParent}> |
| 121 | + <ScrollView |
| 122 | + style={styles.fillParent} |
| 123 | + contentContainerStyle={styles.scrollContent}> |
| 124 | + <View style={[styles.pageIntro, { borderColor: accent }]}> |
| 125 | + <Text style={styles.pageTitle}>{label}</Text> |
| 126 | + <Text style={styles.pageSubtitle}> |
| 127 | + Scroll this page after switching tabs. The tab bar should minimize |
| 128 | + using the currently active marker. |
| 129 | + </Text> |
| 130 | + </View> |
| 131 | + {Array.from({ length: ITEM_COUNT }, (_, index) => ( |
| 132 | + <Rectangle |
| 133 | + key={`${label}-${index}`} |
| 134 | + color={generateNextColor()} |
| 135 | + width={'100%'} |
| 136 | + height={96} |
| 137 | + /> |
| 138 | + ))} |
| 139 | + </ScrollView> |
| 140 | + </ScrollViewMarker> |
| 141 | + </View> |
| 142 | + ); |
| 143 | +} |
| 144 | + |
| 145 | +function PageButton(props: { |
| 146 | + label: string; |
| 147 | + selected: boolean; |
| 148 | + onPress: () => void; |
| 149 | +}) { |
| 150 | + const { label, onPress, selected } = props; |
| 151 | + |
| 152 | + return ( |
| 153 | + <Pressable |
| 154 | + onPress={onPress} |
| 155 | + style={[styles.button, selected ? styles.buttonSelected : undefined]}> |
| 156 | + <Text style={styles.buttonText}>{label}</Text> |
| 157 | + </Pressable> |
| 158 | + ); |
| 159 | +} |
| 160 | + |
| 161 | +const styles = StyleSheet.create({ |
| 162 | + screen: { |
| 163 | + flex: 1, |
| 164 | + backgroundColor: Colors.White, |
| 165 | + }, |
| 166 | + header: { |
| 167 | + paddingTop: 16, |
| 168 | + paddingHorizontal: 16, |
| 169 | + paddingBottom: 12, |
| 170 | + gap: 12, |
| 171 | + }, |
| 172 | + title: { |
| 173 | + fontSize: 17, |
| 174 | + fontWeight: '700', |
| 175 | + }, |
| 176 | + controls: { |
| 177 | + flexDirection: 'row', |
| 178 | + gap: 12, |
| 179 | + }, |
| 180 | + button: { |
| 181 | + paddingVertical: 10, |
| 182 | + paddingHorizontal: 14, |
| 183 | + borderRadius: 10, |
| 184 | + backgroundColor: '#E5E7EB', |
| 185 | + }, |
| 186 | + buttonSelected: { |
| 187 | + backgroundColor: '#CBD5E1', |
| 188 | + }, |
| 189 | + buttonText: { |
| 190 | + fontSize: 14, |
| 191 | + fontWeight: '600', |
| 192 | + }, |
| 193 | + pagerHost: { |
| 194 | + flex: 1, |
| 195 | + }, |
| 196 | + pageContainer: { |
| 197 | + ...StyleSheet.absoluteFillObject, |
| 198 | + }, |
| 199 | + fillParent: { |
| 200 | + flex: 1, |
| 201 | + width: '100%', |
| 202 | + height: '100%', |
| 203 | + }, |
| 204 | + scrollContent: { |
| 205 | + padding: 16, |
| 206 | + gap: 12, |
| 207 | + }, |
| 208 | + pageIntro: { |
| 209 | + padding: 16, |
| 210 | + borderRadius: 12, |
| 211 | + borderWidth: 2, |
| 212 | + backgroundColor: '#F8FAFC', |
| 213 | + gap: 6, |
| 214 | + }, |
| 215 | + pageTitle: { |
| 216 | + fontSize: 16, |
| 217 | + fontWeight: '700', |
| 218 | + }, |
| 219 | + pageSubtitle: { |
| 220 | + fontSize: 14, |
| 221 | + color: '#475569', |
| 222 | + }, |
| 223 | + placeholderScrollContent: { |
| 224 | + padding: 16, |
| 225 | + gap: 12, |
| 226 | + }, |
| 227 | + placeholderText: { |
| 228 | + fontSize: 16, |
| 229 | + fontWeight: '600', |
| 230 | + }, |
| 231 | +}); |
0 commit comments