|
| 1 | +import React from 'react'; |
| 2 | +import { View, Text } from 'react-native'; |
| 3 | +import { NavigationComponent, NavigationProps, Navigation as Nav } from 'react-native-navigation'; |
| 4 | +import Button from '../components/Button'; |
| 5 | +import Root from '../components/Root'; |
| 6 | +import Navigation from '../services/Navigation'; |
| 7 | +import testIDs from '../testIDs'; |
| 8 | + |
| 9 | +const { |
| 10 | + TOPBAR_TITLE_TEXT, |
| 11 | + TOPBAR_TITLE_AVATAR, |
| 12 | + SET_TOPBAR_WITH_SUBTITLE_BTN, |
| 13 | + SET_TOPBAR_WITHOUT_SUBTITLE_BTN, |
| 14 | +} = testIDs; |
| 15 | + |
| 16 | +// TopBar title component WITH subtitle |
| 17 | +function TopBarWithSubtitle() { |
| 18 | + return ( |
| 19 | + <View style={{ flex: 1 }}> |
| 20 | + <View style={{ flexDirection: 'row' }}> |
| 21 | + <View |
| 22 | + testID={TOPBAR_TITLE_AVATAR} |
| 23 | + style={{ alignSelf: 'center', marginRight: 20, width: 10, height: 10, backgroundColor: 'red' }} |
| 24 | + /> |
| 25 | + <View style={{ flex: 1, justifyContent: 'center' }}> |
| 26 | + <Text testID={TOPBAR_TITLE_TEXT} numberOfLines={1}> |
| 27 | + Title - pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas sed |
| 28 | + </Text> |
| 29 | + <Text numberOfLines={1}>Subtitle</Text> |
| 30 | + </View> |
| 31 | + </View> |
| 32 | + </View> |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +// TopBar title component WITHOUT subtitle - this triggers the bug on Android |
| 37 | +function TopBarWithoutSubtitle() { |
| 38 | + return ( |
| 39 | + <View style={{ flex: 1 }}> |
| 40 | + <View style={{ flexDirection: 'row' }}> |
| 41 | + <View |
| 42 | + testID={TOPBAR_TITLE_AVATAR} |
| 43 | + style={{ alignSelf: 'center', marginRight: 20, width: 10, height: 10, backgroundColor: 'red' }} |
| 44 | + /> |
| 45 | + <View style={{ flex: 1, justifyContent: 'center' }}> |
| 46 | + <Text testID={TOPBAR_TITLE_TEXT} numberOfLines={1}> |
| 47 | + Title - pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas sed |
| 48 | + </Text> |
| 49 | + {/* No subtitle - this causes the bug on Android */} |
| 50 | + </View> |
| 51 | + </View> |
| 52 | + </View> |
| 53 | + ); |
| 54 | +} |
| 55 | + |
| 56 | +Nav.registerComponent('TopBarWithSubtitle', () => TopBarWithSubtitle); |
| 57 | +Nav.registerComponent('TopBarWithoutSubtitle', () => TopBarWithoutSubtitle); |
| 58 | + |
| 59 | +interface Props extends NavigationProps { } |
| 60 | + |
| 61 | +export default class TopBarTitleTestScreen extends NavigationComponent<Props> { |
| 62 | + static options() { |
| 63 | + return { |
| 64 | + topBar: { |
| 65 | + title: { |
| 66 | + component: { |
| 67 | + name: 'TopBarWithSubtitle', |
| 68 | + alignment: 'fill', |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }; |
| 73 | + } |
| 74 | + |
| 75 | + constructor(props: Props) { |
| 76 | + super(props); |
| 77 | + Navigation.events().bindComponent(this); |
| 78 | + } |
| 79 | + |
| 80 | + render() { |
| 81 | + return ( |
| 82 | + <Root componentId={this.props.componentId}> |
| 83 | + <Button |
| 84 | + label="With Subtitle" |
| 85 | + testID={SET_TOPBAR_WITH_SUBTITLE_BTN} |
| 86 | + onPress={this.setTopBarWithSubtitle} |
| 87 | + /> |
| 88 | + <Button |
| 89 | + label="Without Subtitle (Bug Test)" |
| 90 | + testID={SET_TOPBAR_WITHOUT_SUBTITLE_BTN} |
| 91 | + platform="android" |
| 92 | + onPress={this.setTopBarWithoutSubtitle} |
| 93 | + /> |
| 94 | + </Root> |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + setTopBarWithSubtitle = () => |
| 99 | + Navigation.mergeOptions(this, { |
| 100 | + topBar: { |
| 101 | + title: { |
| 102 | + component: { |
| 103 | + name: 'TopBarWithSubtitle', |
| 104 | + alignment: 'fill', |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }); |
| 109 | + |
| 110 | + setTopBarWithoutSubtitle = () => |
| 111 | + Navigation.mergeOptions(this, { |
| 112 | + topBar: { |
| 113 | + title: { |
| 114 | + component: { |
| 115 | + name: 'TopBarWithoutSubtitle', |
| 116 | + alignment: 'fill', |
| 117 | + }, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }); |
| 121 | +} |
| 122 | + |
0 commit comments