Skip to content

Commit 46052f3

Browse files
authored
fix(iOS, Tabs): remove incorrect warning on none environment in Bottom Accessory (#3416)
## Description Removes incorrect warning when bottom accessory enters `none` environment. Reasoning is explained here: #3411 (comment). Thanks to @johankasperi for letting us know about the bug. | before | after | | --- | --- | | <video src="https://github.com/user-attachments/assets/92c04ce5-742c-4426-8354-595918e95132" /> | <video src="https://github.com/user-attachments/assets/6e7c191d-f76d-4640-80df-3d7514451bfe" /> Supersedes #3411. ## Changes - remove warning ## Test code and steps to reproduce Run `Test3288`. Hide the bottom accessory. ## Checklist - [x] Included code example that can be used to test this change - [ ] Ensured that CI passes
1 parent 9e066ad commit 46052f3

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

ios/bottom-tabs/accessory/RNSBottomTabsAccessoryEventEmitter.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ - (BOOL)emitOnEnvironmentChangeIfNeeded:(UITabAccessoryEnvironment)environment A
4444
rnscreens::conversion::RNSBottomTabsAccessoryOnEnvironmentChangePayloadFromUITabAccessoryEnvironment(
4545
environment);
4646

47-
_reactEventEmitter->onEnvironmentChange({.environment = payloadEnvironment});
47+
// If environment is other than `regular` or `inline`, we don't emit the event.
48+
if (!payloadEnvironment.has_value()) {
49+
return NO;
50+
}
51+
52+
_reactEventEmitter->onEnvironmentChange({.environment = payloadEnvironment.value()});
4853
return YES;
4954
} else {
5055
RCTLogWarn(@"[RNScreens] Skipped OnEnvironmentChange event emission due to nullish emitter");
@@ -56,6 +61,11 @@ - (BOOL)emitOnEnvironmentChangeIfNeeded:(UITabAccessoryEnvironment)environment A
5661
rnscreens::conversion::RNSBottomTabsAccessoryOnEnvironmentChangePayloadFromUITabAccessoryEnvironment(
5762
environment);
5863

64+
// If environment is other than `regular` or `inline`, we don't emit the event.
65+
if (environmentString == nil) {
66+
return NO;
67+
}
68+
5969
self.onEnvironmentChange(@{@"environment" : environmentString});
6070
return YES;
6171
} else {

ios/conversion/RNSConversions-BottomTabs.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ RNSScrollEdgeEffect RNSBottomTabsScrollEdgeEffectFromBottomTabsScreenTopScrollEd
405405

406406
#if RCT_NEW_ARCH_ENABLED
407407
API_AVAILABLE(ios(26.0))
408-
react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment
408+
std::optional<react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment>
409409
RNSBottomTabsAccessoryOnEnvironmentChangePayloadFromUITabAccessoryEnvironment(UITabAccessoryEnvironment environment)
410410
{
411411
switch (environment) {
@@ -414,8 +414,8 @@ RNSScrollEdgeEffect RNSBottomTabsScrollEdgeEffectFromBottomTabsScreenTopScrollEd
414414
case UITabAccessoryEnvironmentInline:
415415
return react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment::Inline;
416416
default:
417-
RCTLogError(@"[RNScreens] Unsupported environment for onEnvironmentChange event");
418-
return react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment::Regular;
417+
// We want to ignore other environments (e.g. `none`), that's why there is no warning here.
418+
return std::nullopt;
419419
}
420420
}
421421

@@ -446,7 +446,7 @@ RNSBottomTabsAccessoryEnvironment RNSBottomTabsAccessoryEnvironmentFromCppEquiva
446446
NSString *RNSBottomTabsAccessoryOnEnvironmentChangePayloadFromUITabAccessoryEnvironment(
447447
UITabAccessoryEnvironment environment)
448448
{
449-
NSString *environmentString = nil;
449+
NSString *environmentString;
450450
switch (environment) {
451451
case UITabAccessoryEnvironmentRegular:
452452
environmentString = BOTTOM_TABS_ACCESSORY_REGULAR_ENVIRONMENT;
@@ -455,7 +455,8 @@ RNSBottomTabsAccessoryEnvironment RNSBottomTabsAccessoryEnvironmentFromCppEquiva
455455
environmentString = BOTTOM_TABS_ACCESSORY_INLINE_ENVIRONMENT;
456456
break;
457457
default:
458-
RCTLogError(@"[RNScreens] Unsupported environment for onEnvironmentChange event");
458+
// We want to ignore other environments (e.g. `none`), that's why there is no warning here.
459+
environmentString = nil;
459460
break;
460461
}
461462

ios/conversion/RNSConversions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ RNSScrollEdgeEffect RNSBottomTabsScrollEdgeEffectFromBottomTabsScreenTopScrollEd
7777

7878
#if RCT_NEW_ARCH_ENABLED
7979
API_AVAILABLE(ios(26.0))
80-
react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment
80+
std::optional<react::RNSBottomTabsAccessoryEventEmitter::OnEnvironmentChangeEnvironment>
8181
RNSBottomTabsAccessoryOnEnvironmentChangePayloadFromUITabAccessoryEnvironment(UITabAccessoryEnvironment environment);
8282

8383
#if REACT_NATIVE_VERSION_MINOR >= 82

0 commit comments

Comments
 (0)