Skip to content

Commit

Permalink
Fix SearchBar false render (#6317)
Browse files Browse the repository at this point in the history
This PR fixes #4443 

The problem was that `withDefault.topBar.searchBar.hasValue` was true when setting `topBar.searchBar = false`.
  • Loading branch information
jinshin1013 authored Jun 22, 2020
1 parent fbb72f2 commit 58674e8
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ @implementation RNNComponentPresenter {
}

- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
self = [super initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
_topBarTitlePresenter = [[TopBarTitlePresenter alloc] initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
return self;
self = [super initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
_topBarTitlePresenter = [[TopBarTitlePresenter alloc] initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
return self;
}

- (void)bindViewController:(id)boundViewController {
[super bindViewController:boundViewController];
[_topBarTitlePresenter bindViewController:boundViewController];
_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:boundViewController componentRegistry:self.componentRegistry];
[super bindViewController:boundViewController];
[_topBarTitlePresenter bindViewController:boundViewController];
_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:boundViewController componentRegistry:self.componentRegistry];
}

- (void)componentDidAppear {
Expand All @@ -43,37 +43,37 @@ - (void)componentDidDisappear {
}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
[super applyOptionsOnWillMoveToParentViewController:options];
[super applyOptionsOnWillMoveToParentViewController:options];
}

- (void)applyOptions:(RNNNavigationOptions *)options {
[super applyOptions:options];
UIViewController* viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
[viewController setBackgroundImage:[withDefault.backgroundImage getWithDefaultValue:nil]];
[viewController setTopBarPrefersLargeTitle:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
[viewController setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]];
[viewController setStatusBarBlur:[withDefault.statusBar.blur getWithDefaultValue:NO]];
[viewController setStatusBarStyle:[withDefault.statusBar.style getWithDefaultValue:@"default"] animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
[viewController setBackButtonVisible:[withDefault.topBar.backButton.visible getWithDefaultValue:YES]];
[viewController setInterceptTouchOutside:[withDefault.overlay.interceptTouchOutside getWithDefaultValue:YES]];
[super applyOptions:options];
UIViewController* viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
[viewController setBackgroundImage:[withDefault.backgroundImage getWithDefaultValue:nil]];
[viewController setTopBarPrefersLargeTitle:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
[viewController setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]];
[viewController setStatusBarBlur:[withDefault.statusBar.blur getWithDefaultValue:NO]];
[viewController setStatusBarStyle:[withDefault.statusBar.style getWithDefaultValue:@"default"] animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
[viewController setBackButtonVisible:[withDefault.topBar.backButton.visible getWithDefaultValue:YES]];
[viewController setInterceptTouchOutside:[withDefault.overlay.interceptTouchOutside getWithDefaultValue:YES]];

if (@available(iOS 13.0, *)) {
[viewController setBackgroundColor:[withDefault.layout.componentBackgroundColor getWithDefaultValue:UIColor.systemBackgroundColor]];
} else {
[viewController setBackgroundColor:[withDefault.layout.componentBackgroundColor getWithDefaultValue:viewController.view.backgroundColor]];
}

if (withDefault.topBar.searchBar.hasValue) {
BOOL hideNavBarOnFocusSearchBar = YES;
if (withDefault.topBar.hideNavBarOnFocusSearchBar.hasValue) {
hideNavBarOnFocusSearchBar = withDefault.topBar.hideNavBarOnFocusSearchBar.get;
}
[viewController setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}
[_topBarTitlePresenter applyOptions:withDefault.topBar];
if ([withDefault.topBar.searchBar getWithDefaultValue:NO]) {
BOOL hideNavBarOnFocusSearchBar = YES;
if (withDefault.topBar.hideNavBarOnFocusSearchBar.hasValue) {
hideNavBarOnFocusSearchBar = withDefault.topBar.hideNavBarOnFocusSearchBar.get;
}
[viewController setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}
[_topBarTitlePresenter applyOptions:withDefault.topBar];
}

- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
Expand All @@ -92,72 +92,72 @@ - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {

- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
[super mergeOptions:options resolvedOptions:currentOptions];
RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[currentOptions overrideOptions:options] withDefault:[self defaultOptions]];
UIViewController* viewController = self.boundViewController;
RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[currentOptions overrideOptions:options] withDefault:[self defaultOptions]];
UIViewController* viewController = self.boundViewController;

if (options.backgroundImage.hasValue) {
[viewController setBackgroundImage:options.backgroundImage.get];
}
if (options.topBar.searchBar.hasValue) {
BOOL hideNavBarOnFocusSearchBar = YES;
if (options.topBar.hideNavBarOnFocusSearchBar.hasValue) {
hideNavBarOnFocusSearchBar = options.topBar.hideNavBarOnFocusSearchBar.get;
}
[viewController setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}
if (options.backgroundImage.hasValue) {
[viewController setBackgroundImage:options.backgroundImage.get];
}
if ([withDefault.topBar.searchBar getWithDefaultValue:NO]) {
BOOL hideNavBarOnFocusSearchBar = YES;
if (options.topBar.hideNavBarOnFocusSearchBar.hasValue) {
hideNavBarOnFocusSearchBar = options.topBar.hideNavBarOnFocusSearchBar.get;
}
[viewController setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}

if (options.topBar.drawBehind.hasValue) {
[viewController setDrawBehindTopBar:options.topBar.drawBehind.get];
if (options.topBar.drawBehind.hasValue) {
[viewController setDrawBehindTopBar:options.topBar.drawBehind.get];
}

if (options.bottomTabs.drawBehind.hasValue) {
[viewController setDrawBehindTabBar:options.bottomTabs.drawBehind.get];
}

if (options.topBar.title.text.hasValue) {
[viewController setNavigationItemTitle:options.topBar.title.text.get];
}
[viewController setNavigationItemTitle:options.topBar.title.text.get];
}

if (options.topBar.largeTitle.visible.hasValue) {
[viewController setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
}
if (options.topBar.largeTitle.visible.hasValue) {
[viewController setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
}

if (options.layout.componentBackgroundColor.hasValue) {
[viewController setBackgroundColor:options.layout.componentBackgroundColor.get];
}

if (options.bottomTab.badgeColor.hasValue) {
[viewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
}
if (options.bottomTab.visible.hasValue) {
[viewController.tabBarController setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
}
if (options.statusBar.blur.hasValue) {
[viewController setStatusBarBlur:options.statusBar.blur.get];
}
if (options.statusBar.style.hasValue) {
[viewController setStatusBarStyle:options.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
}
if (options.topBar.backButton.visible.hasValue) {
[viewController setBackButtonVisible:options.topBar.backButton.visible.get];
}
if (options.topBar.leftButtons || options.topBar.rightButtons) {
[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
}

if (options.overlay.interceptTouchOutside.hasValue) {
RCTRootView* rootView = (RCTRootView*)viewController.view;
rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
}
[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:withDefault.topBar];
if (options.bottomTab.badgeColor.hasValue) {
[viewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
}
if (options.bottomTab.visible.hasValue) {
[viewController.tabBarController setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
}
if (options.statusBar.blur.hasValue) {
[viewController setStatusBarBlur:options.statusBar.blur.get];
}
if (options.statusBar.style.hasValue) {
[viewController setStatusBarStyle:options.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
}
if (options.topBar.backButton.visible.hasValue) {
[viewController setBackButtonVisible:options.topBar.backButton.visible.get];
}
if (options.topBar.leftButtons || options.topBar.rightButtons) {
[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
}

if (options.overlay.interceptTouchOutside.hasValue) {
RCTRootView* rootView = (RCTRootView*)viewController.view;
rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
}
[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:withDefault.topBar];
}

- (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
Expand All @@ -167,6 +167,6 @@ - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewRe


- (void)dealloc {
[self.componentRegistry clearComponentsForParentId:self.boundComponentId];
[self.componentRegistry clearComponentsForParentId:self.boundComponentId];
}
@end

0 comments on commit 58674e8

Please sign in to comment.