Skip to content

Conversation

@kligarski
Copy link
Contributor

@kligarski kligarski commented Sep 12, 2025

Description

Follow-up to #3199.

Adds support for using native behavior in hideNavigationBar, obscureBackground props in SearchBar.

This will require changes in react-navigation docs - ticket for this: https://github.com/software-mansion/react-native-screens-labs/issues/384.

Values table

obscureBackground JS prop (initial) prop value passed to native controller setting
undefined RNSOptionalBooleanUndefined native behavior
true RNSOptionalBooleanTrue true
false RNSOptionalBooleanFalse false

Changes from true/false to undefined in runtime are unsupported.

Native behavior

obscureBackground

/* On iOS, default is NO for apps linked on iOS 15.0 and later, YES otherwise.
 On tvOS, default is NO when contained in UISearchContainerViewController, YES otherwise.
 */
@property (nonatomic, assign) BOOL obscuresBackgroundDuringPresentation API_AVAILABLE(ios(9.1));

hideNavigationBar

/// Default is `YES` for apps linked before iOS 26.0, other than on MacCatalyst, where the default is `NO`.
/// On iOS 26.0 for apps linked on iOS 26.0 and later, the value is determined by context unless directly set through the API. The default remains `NO` on MacCatalyst.
@property (nonatomic, assign) BOOL hidesNavigationBarDuringPresentation;

Closes https://github.com/software-mansion/react-native-screens-labs/issues/415.

Changes

  • change native component to use enum for obscureBackground and hideNavigationBar
  • add util converting boolean | undefined to 'undefined' | 'true' | 'false'
  • add RNSOptionalBoolean enum and conversions for Paper and Fabric
  • change native prop setters to handle enum
  • add warning for dynamic change back to undefined

Test code and steps to reproduce

Run Test758. You can comment out obscureBackground, hideNavigationBar props before running the test.

Checklist

Comment on lines +159 to +198
- (void)setObscureBackground:(RNSOptionalBoolean)obscureBackground
{
[_controller setObscuresBackgroundDuringPresentation:obscureBackground];
switch (obscureBackground) {
case RNSOptionalBooleanTrue:
[_controller setObscuresBackgroundDuringPresentation:YES];
_isObscureBackgroundSet = YES;
break;

case RNSOptionalBooleanFalse:
[_controller setObscuresBackgroundDuringPresentation:NO];
_isObscureBackgroundSet = YES;
break;

default:
if (_isObscureBackgroundSet) {
RCTLogWarn(@"[RNScreens] Dynamically restoring obscureBackground to default native behavior is unsupported.");
}
break;
}
}

- (void)setHideNavigationBar:(BOOL)hideNavigationBar
- (void)setHideNavigationBar:(RNSOptionalBoolean)hideNavigationBar
{
[_controller setHidesNavigationBarDuringPresentation:hideNavigationBar];
switch (hideNavigationBar) {
case RNSOptionalBooleanTrue:
[_controller setHidesNavigationBarDuringPresentation:YES];
_isHideNavigationBarSet = YES;
break;

case RNSOptionalBooleanFalse:
[_controller setHidesNavigationBarDuringPresentation:NO];
_isHideNavigationBarSet = YES;
break;

default:
if (_isHideNavigationBarSet) {
RCTLogWarn(@"[RNScreens] Dynamically restoring hideNavigationBar to default native behavior is unsupported.");
}
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be relatively easy to refactor out to some helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed internally, we decided to leave it as it is for now to maintain readability. If we use RNSOptionalBoolean more in the future, we can consider creating a macro.

Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside the fact, that we could maybe refactor out some parts in RNSSearchBar implementation, this PR looks really good. Thank you! Let's create follow-up for react-navigation.

@kligarski kligarski merged commit 374aab2 into main Sep 17, 2025
9 checks passed
@kligarski kligarski deleted the @kligarski/search-bar-defaults-3 branch September 17, 2025 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants