11import React from 'react' ;
2+ import { Platform } from 'react-native' ;
23import { NavigationProps } from 'react-native-navigation' ;
34
45import Root from '../components/Root' ;
56import Button from '../components/Button' ;
67import Navigation from '../services/Navigation' ;
78import testIDs from '../testIDs' ;
89
9- const { HIDE_TOP_BAR_BTN , SHOW_TOP_BAR_BTN , SHOW_SEARCH_BAR_BTN , HIDE_SEARCH_BAR_BTN , TOP_BAR } =
10+ const { HIDE_TOP_BAR_BTN , SHOW_TOP_BAR_BTN , SHOW_SEARCH_BAR_BTN , HIDE_SEARCH_BAR_BTN , TOP_BAR , TOGGLE_PLACEMENT_BTN } =
1011 testIDs ;
1112
12- interface Props extends NavigationProps { }
13+ interface Props extends NavigationProps { }
1314
1415export default class SearchBar extends React . Component < Props > {
1516 static options ( ) {
@@ -26,6 +27,7 @@ export default class SearchBar extends React.Component<Props> {
2627
2728 state = {
2829 isAndroidNavigationBarVisible : true ,
30+ placement : 'stacked' as 'stacked' | 'integrated' ,
2931 } ;
3032
3133 render ( ) {
@@ -35,6 +37,13 @@ export default class SearchBar extends React.Component<Props> {
3537 < Button label = "Show TopBar" testID = { SHOW_TOP_BAR_BTN } onPress = { this . showTopBar } />
3638 < Button label = "Hide SearchBar" testID = { HIDE_SEARCH_BAR_BTN } onPress = { this . hideSearchBar } />
3739 < Button label = "Show SearchBar" testID = { SHOW_SEARCH_BAR_BTN } onPress = { this . showSearchBar } />
40+ { parseInt ( String ( Platform . Version ) , 10 ) >= 26 && (
41+ < Button
42+ label = { `Toggle Placement (${ this . state . placement } )` }
43+ testID = { TOGGLE_PLACEMENT_BTN }
44+ onPress = { this . togglePlacement }
45+ />
46+ ) }
3847 </ Root >
3948 ) ;
4049 }
@@ -67,7 +76,27 @@ export default class SearchBar extends React.Component<Props> {
6776 topBar : {
6877 searchBar : {
6978 visible : true ,
79+ placement : this . state . placement ,
7080 } ,
7181 } ,
7282 } ) ;
83+
84+ togglePlacement = ( ) => {
85+ const newPlacement = this . state . placement === 'stacked' ? 'integrated' : 'stacked' ;
86+ this . setState ( { placement : newPlacement } ) ;
87+ Navigation . mergeOptions ( this , {
88+ topBar : {
89+ searchBar : {
90+ visible : false ,
91+ } ,
92+ } ,
93+ } ) ;
94+ Navigation . mergeOptions ( this , {
95+ topBar : {
96+ searchBar : {
97+ placement : newPlacement ,
98+ } ,
99+ } ,
100+ } ) ;
101+ } ;
73102}
0 commit comments