Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): extraLight blur not working #2338

Merged
merged 9 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions apps/src/tests/Test2320.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from "react";
import { ScrollView, Text } from "react-native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NavigationContainer, useTheme } from "@react-navigation/native";
import { SafeAreaProvider } from "react-native-safe-area-context";

const ArticleScreen = () => {
return (
<ScrollView contentInsetAdjustmentBehavior="automatic">
<Text style={{ fontSize: 30 }}>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry&apos;s standard dummy text
ever since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
Contrary to popular belief, Lorem Ipsum is not simply random text. It
has roots in a piece of classical Latin literature from 45 BC, making it
over 2000 years old. Richard McClintock, a Latin professor at
Hampden-Sydney College in Virginia, looked up one of the more obscure
Latin words, consectetur, from a Lorem Ipsum passage, and going through
the cites of the word in classical literature, discovered the
undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33
of &quot;de Finibus Bonorum et Malorum&quot; (The Extremes of Good and
Evil) by Cicero, written in 45 BC. This book is a treatise on the theory
of ethics, very popular during the Renaissance. The first line of Lorem
Ipsum, &quot;Lorem ipsum dolor sit amet..&quot;, comes from a line in
section 1.10.32.
</Text>
</ScrollView>
);
}

export default function App() {
const Stack = createNativeStackNavigator();
return (
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Article"
component={ArticleScreen}
options={{
headerTransparent: true,
headerBlurEffect: "extraLight",
headerLargeTitle: true
}}
/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
)
}
1 change: 1 addition & 0 deletions apps/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export { default as Test2252 } from './Test2252';
export { default as Test2271 } from './Test2271';
export { default as Test2282 } from './Test2282';
export { default as Test2317 } from './Test2317';
export { default as Test2320 } from './Test2320';
export { default as Test2332 } from './Test2332';
export { default as Test2395 } from './Test2395';
export { default as TestScreenAnimation } from './TestScreenAnimation';
Expand Down
6 changes: 5 additions & 1 deletion ios/RNSConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ namespace react = facebook::react;

+ (NSMutableArray<NSNumber *> *)arrayFromVector:(const std::vector<CGFloat> &)vector;

+ (UIBlurEffectStyle)UIBlurEffectStyleFromCppEquivalent:(react::RNSScreenStackHeaderConfigBlurEffect)blurEffect;
+ (RNSBlurEffectStyle)RNSBlurEffectStyleFromCppEquivalent:(react::RNSScreenStackHeaderConfigBlurEffect)blurEffect;

/// This method fails (by assertion) when `blurEffect == RNSBlurEffectStyleNone` which has no counter part in the UIKit
/// type.
+ (UIBlurEffectStyle)tryConvertRNSBlurEffectStyleToUIBlurEffectStyle:(RNSBlurEffectStyle)blurEffect;

@end

Expand Down
64 changes: 38 additions & 26 deletions ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,71 +173,83 @@ + (RNSSearchBarPlacement)RNSScreenSearchBarPlacementFromCppEquivalent:(react::RN
return array;
}

+ (UIBlurEffectStyle)UIBlurEffectStyleFromCppEquivalent:(react::RNSScreenStackHeaderConfigBlurEffect)blurEffect
+ (RNSBlurEffectStyle)RNSBlurEffectStyleFromCppEquivalent:(react::RNSScreenStackHeaderConfigBlurEffect)blurEffect
{
#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
switch (blurEffect) {
case react::RNSScreenStackHeaderConfigBlurEffect::None:
return RNSBlurEffectStyleNone;
case react::RNSScreenStackHeaderConfigBlurEffect::ExtraLight:
return UIBlurEffectStyleExtraLight;
return RNSBlurEffectStyleExtraLight;
case react::RNSScreenStackHeaderConfigBlurEffect::Light:
return UIBlurEffectStyleLight;
return RNSBlurEffectStyleLight;
case react::RNSScreenStackHeaderConfigBlurEffect::Dark:
return UIBlurEffectStyleDark;
return RNSBlurEffectStyleDark;
case react::RNSScreenStackHeaderConfigBlurEffect::Regular:
return UIBlurEffectStyleRegular;
return RNSBlurEffectStyleRegular;
case react::RNSScreenStackHeaderConfigBlurEffect::Prominent:
return UIBlurEffectStyleProminent;
return RNSBlurEffectStyleProminent;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemUltraThinMaterial:
return UIBlurEffectStyleSystemUltraThinMaterial;
return RNSBlurEffectStyleSystemUltraThinMaterial;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThinMaterial:
return UIBlurEffectStyleSystemThinMaterial;
return RNSBlurEffectStyleSystemThinMaterial;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemMaterial:
return UIBlurEffectStyleSystemMaterial;
return RNSBlurEffectStyleSystemMaterial;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThickMaterial:
return UIBlurEffectStyleSystemThickMaterial;
return RNSBlurEffectStyleSystemThickMaterial;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemChromeMaterial:
return UIBlurEffectStyleSystemChromeMaterial;
return RNSBlurEffectStyleSystemChromeMaterial;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemUltraThinMaterialLight:
return UIBlurEffectStyleSystemUltraThinMaterialLight;
return RNSBlurEffectStyleSystemUltraThinMaterialLight;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThinMaterialLight:
return UIBlurEffectStyleSystemThinMaterialLight;
return RNSBlurEffectStyleSystemThinMaterialLight;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemMaterialLight:
return UIBlurEffectStyleSystemMaterialLight;
return RNSBlurEffectStyleSystemMaterialLight;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThickMaterialLight:
return UIBlurEffectStyleSystemThickMaterialLight;
return RNSBlurEffectStyleSystemThickMaterialLight;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemChromeMaterialLight:
return UIBlurEffectStyleSystemChromeMaterialLight;
return RNSBlurEffectStyleSystemChromeMaterialLight;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemUltraThinMaterialDark:
return UIBlurEffectStyleSystemUltraThinMaterialDark;
return RNSBlurEffectStyleSystemUltraThinMaterialDark;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThinMaterialDark:
return UIBlurEffectStyleSystemThinMaterialDark;
return RNSBlurEffectStyleSystemThinMaterialDark;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemMaterialDark:
return UIBlurEffectStyleSystemMaterialDark;
return RNSBlurEffectStyleSystemMaterialDark;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemThickMaterialDark:
return UIBlurEffectStyleSystemThickMaterialDark;
return RNSBlurEffectStyleSystemThickMaterialDark;
case react::RNSScreenStackHeaderConfigBlurEffect::SystemChromeMaterialDark:
return UIBlurEffectStyleSystemChromeMaterialDark;
return RNSBlurEffectStyleSystemChromeMaterialDark;
}
}
#endif

switch (blurEffect) {
case react::RNSScreenStackHeaderConfigBlurEffect::None:
return RNSBlurEffectStyleNone;
case react::RNSScreenStackHeaderConfigBlurEffect::Light:
return UIBlurEffectStyleLight;
return RNSBlurEffectStyleLight;
case react::RNSScreenStackHeaderConfigBlurEffect::Dark:
return UIBlurEffectStyleDark;
return RNSBlurEffectStyleDark;
case react::RNSScreenStackHeaderConfigBlurEffect::Regular:
return UIBlurEffectStyleRegular;
return RNSBlurEffectStyleRegular;
case react::RNSScreenStackHeaderConfigBlurEffect::Prominent:
return UIBlurEffectStyleProminent;
return RNSBlurEffectStyleProminent;
case react::RNSScreenStackHeaderConfigBlurEffect::ExtraLight:
default:
return UIBlurEffectStyleExtraLight;
return RNSBlurEffectStyleNone;
}
}

+ (UIBlurEffectStyle)tryConvertRNSBlurEffectStyleToUIBlurEffectStyle:(RNSBlurEffectStyle)blurEffect
{
react_native_assert(blurEffect != RNSBlurEffectStyleNone);
// Cast safety: RNSBlurEffectStyle is defined in such way that its values map 1:1 with
// UIBlurEffectStyle, except RNSBlurEffectStyleNone which is excluded above.
return (UIBlurEffectStyle)blurEffect;
}

@end

#endif // RCT_NEW_ARCH_ENABLED
46 changes: 46 additions & 0 deletions ios/RNSEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,49 @@ typedef NS_ENUM(NSInteger, RNSSearchBarPlacement) {
RNSSearchBarPlacementInline,
RNSSearchBarPlacementStacked,
};

// Redefinition of UIBlurEffectStyle. We need to represent additional case of `None`.
typedef NS_ENUM(NSInteger, RNSBlurEffectStyle) {
/// No blur effect should be visible
RNSBlurEffectStyleNone = -1,
RNSBlurEffectStyleExtraLight = UIBlurEffectStyleExtraLight,
RNSBlurEffectStyleLight = UIBlurEffectStyleLight,
RNSBlurEffectStyleDark = UIBlurEffectStyleDark,
// TODO: Add support for this variant on tvOS
// RNSBlurEffectStyleExtraDark = UIBlurEffectStyleExtraDark API_AVAILABLE(tvos(10.0)) API_UNAVAILABLE(ios)
// API_UNAVAILABLE(watchos),
RNSBlurEffectStyleRegular API_AVAILABLE(ios(10.0)) API_UNAVAILABLE(watchos) = UIBlurEffectStyleRegular,
RNSBlurEffectStyleProminent API_AVAILABLE(ios(10.0)) API_UNAVAILABLE(watchos) = UIBlurEffectStyleProminent,
RNSBlurEffectStyleSystemUltraThinMaterial API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemUltraThinMaterial,
RNSBlurEffectStyleSystemThinMaterial API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThinMaterial,
RNSBlurEffectStyleSystemMaterial API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemMaterial,
RNSBlurEffectStyleSystemThickMaterial API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThickMaterial,
RNSBlurEffectStyleSystemChromeMaterial API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemChromeMaterial,
RNSBlurEffectStyleSystemUltraThinMaterialLight API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemUltraThinMaterialLight,
RNSBlurEffectStyleSystemThinMaterialLight API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThinMaterialLight,
RNSBlurEffectStyleSystemMaterialLight API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemMaterialLight,
RNSBlurEffectStyleSystemThickMaterialLight API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThickMaterialLight,
RNSBlurEffectStyleSystemChromeMaterialLight API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemChromeMaterialLight,

RNSBlurEffectStyleSystemUltraThinMaterialDark API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemUltraThinMaterialDark,
RNSBlurEffectStyleSystemThinMaterialDark API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThinMaterialDark,
RNSBlurEffectStyleSystemMaterialDark API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemMaterialDark,
RNSBlurEffectStyleSystemThickMaterialDark API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemThickMaterialDark,
RNSBlurEffectStyleSystemChromeMaterialDark API_AVAILABLE(ios(13.0))
API_UNAVAILABLE(watchos, tvos) = UIBlurEffectStyleSystemChromeMaterialDark

} API_AVAILABLE(ios(8.0)) API_UNAVAILABLE(watchos);
2 changes: 1 addition & 1 deletion ios/RNSScreenStackHeaderConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@property (nonatomic) BOOL backButtonInCustomView;
@property (nonatomic) UISemanticContentAttribute direction;
@property (nonatomic) UINavigationItemBackButtonDisplayMode backButtonDisplayMode;
@property (nonatomic) UIBlurEffectStyle blurEffect;
@property (nonatomic) RNSBlurEffectStyle blurEffect;

+ (void)willShowViewController:(UIViewController *)vc
animated:(BOOL)animated
Expand Down
55 changes: 30 additions & 25 deletions ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
self.hidden = YES;
_reactSubviews = [NSMutableArray new];
_backTitleVisible = YES;
_blurEffect = RNSBlurEffectStyleNone;
}

- (UIView *)reactSuperview
Expand Down Expand Up @@ -449,8 +450,11 @@
appearance.backgroundColor = config.backgroundColor;
}

if (config.blurEffect) {
appearance.backgroundEffect = [UIBlurEffect effectWithStyle:config.blurEffect];
if (config.blurEffect != RNSBlurEffectStyleNone) {
appearance.backgroundEffect =
[UIBlurEffect effectWithStyle:[RNSConvert tryConvertRNSBlurEffectStyleToUIBlurEffectStyle:config.blurEffect]];

Check failure on line 455 in ios/RNSScreenStackHeaderConfig.mm

View workflow job for this annotation

GitHub Actions / build

use of undeclared identifier 'RNSConvert'

Check failure on line 455 in ios/RNSScreenStackHeaderConfig.mm

View workflow job for this annotation

GitHub Actions / build

use of undeclared identifier 'RNSConvert'
} else {
appearance.backgroundEffect = nil;
}

if (config.hideShadow) {
Expand Down Expand Up @@ -977,7 +981,7 @@
_backgroundColor = RCTUIColorFromSharedColor(newScreenProps.backgroundColor);

if (newScreenProps.blurEffect != oldScreenProps.blurEffect) {
_blurEffect = [RNSConvert UIBlurEffectStyleFromCppEquivalent:newScreenProps.blurEffect];
_blurEffect = [RNSConvert RNSBlurEffectStyleFromCppEquivalent:newScreenProps.blurEffect];
}

[self updateViewControllerIfNeeded];
Expand Down Expand Up @@ -1061,7 +1065,7 @@
RCT_EXPORT_VIEW_PROPERTY(backTitleFontSize, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(backTitleVisible, BOOL)
RCT_EXPORT_VIEW_PROPERTY(blurEffect, UIBlurEffectStyle)
RCT_EXPORT_VIEW_PROPERTY(blurEffect, RNSBlurEffectStyle)
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
RCT_EXPORT_VIEW_PROPERTY(direction, UISemanticContentAttribute)
RCT_EXPORT_VIEW_PROPERTY(largeTitle, BOOL)
Expand Down Expand Up @@ -1127,36 +1131,37 @@
{
NSMutableDictionary *blurEffects = [NSMutableDictionary new];
[blurEffects addEntriesFromDictionary:@{
@"extraLight" : @(UIBlurEffectStyleExtraLight),
@"light" : @(UIBlurEffectStyleLight),
@"dark" : @(UIBlurEffectStyleDark),
@"none" : @(RNSBlurEffectStyleNone),
@"extraLight" : @(RNSBlurEffectStyleExtraLight),
@"light" : @(RNSBlurEffectStyleLight),
@"dark" : @(RNSBlurEffectStyleDark),
}];

if (@available(iOS 10.0, *)) {
[blurEffects addEntriesFromDictionary:@{
@"regular" : @(UIBlurEffectStyleRegular),
@"prominent" : @(UIBlurEffectStyleProminent),
@"regular" : @(RNSBlurEffectStyleRegular),
@"prominent" : @(RNSBlurEffectStyleProminent),
}];
}
#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
[blurEffects addEntriesFromDictionary:@{
@"systemUltraThinMaterial" : @(UIBlurEffectStyleSystemUltraThinMaterial),
@"systemThinMaterial" : @(UIBlurEffectStyleSystemThinMaterial),
@"systemMaterial" : @(UIBlurEffectStyleSystemMaterial),
@"systemThickMaterial" : @(UIBlurEffectStyleSystemThickMaterial),
@"systemChromeMaterial" : @(UIBlurEffectStyleSystemChromeMaterial),
@"systemUltraThinMaterialLight" : @(UIBlurEffectStyleSystemUltraThinMaterialLight),
@"systemThinMaterialLight" : @(UIBlurEffectStyleSystemThinMaterialLight),
@"systemMaterialLight" : @(UIBlurEffectStyleSystemMaterialLight),
@"systemThickMaterialLight" : @(UIBlurEffectStyleSystemThickMaterialLight),
@"systemChromeMaterialLight" : @(UIBlurEffectStyleSystemChromeMaterialLight),
@"systemUltraThinMaterialDark" : @(UIBlurEffectStyleSystemUltraThinMaterialDark),
@"systemThinMaterialDark" : @(UIBlurEffectStyleSystemThinMaterialDark),
@"systemMaterialDark" : @(UIBlurEffectStyleSystemMaterialDark),
@"systemThickMaterialDark" : @(UIBlurEffectStyleSystemThickMaterialDark),
@"systemChromeMaterialDark" : @(UIBlurEffectStyleSystemChromeMaterialDark),
@"systemUltraThinMaterial" : @(RNSBlurEffectStyleSystemUltraThinMaterial),
@"systemThinMaterial" : @(RNSBlurEffectStyleSystemThinMaterial),
@"systemMaterial" : @(RNSBlurEffectStyleSystemMaterial),
@"systemThickMaterial" : @(RNSBlurEffectStyleSystemThickMaterial),
@"systemChromeMaterial" : @(RNSBlurEffectStyleSystemChromeMaterial),
@"systemUltraThinMaterialLight" : @(RNSBlurEffectStyleSystemUltraThinMaterialLight),
@"systemThinMaterialLight" : @(RNSBlurEffectStyleSystemThinMaterialLight),
@"systemMaterialLight" : @(RNSBlurEffectStyleSystemMaterialLight),
@"systemThickMaterialLight" : @(RNSBlurEffectStyleSystemThickMaterialLight),
@"systemChromeMaterialLight" : @(RNSBlurEffectStyleSystemChromeMaterialLight),
@"systemUltraThinMaterialDark" : @(RNSBlurEffectStyleSystemUltraThinMaterialDark),
@"systemThinMaterialDark" : @(RNSBlurEffectStyleSystemThinMaterialDark),
@"systemMaterialDark" : @(RNSBlurEffectStyleSystemMaterialDark),
@"systemThickMaterialDark" : @(RNSBlurEffectStyleSystemThickMaterialDark),
@"systemChromeMaterialDark" : @(RNSBlurEffectStyleSystemChromeMaterialDark),
}];
}
#endif
Expand All @@ -1182,6 +1187,6 @@
UINavigationItemBackButtonDisplayModeDefault,
integerValue)

RCT_ENUM_CONVERTER(UIBlurEffectStyle, ([self blurEffectsForIOSVersion]), UIBlurEffectStyleExtraLight, integerValue)
RCT_ENUM_CONVERTER(RNSBlurEffectStyle, ([self blurEffectsForIOSVersion]), RNSBlurEffectStyleNone, integerValue)

@end
3 changes: 2 additions & 1 deletion src/fabric/ScreenStackHeaderConfigNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type OnDetachedEvent = Readonly<{}>;
type BackButtonDisplayMode = 'minimal' | 'default' | 'generic';

type BlurEffect =
| 'none'
| 'extraLight'
| 'light'
| 'dark'
Expand Down Expand Up @@ -68,7 +69,7 @@ export interface NativeProps extends ViewProps {
backButtonDisplayMode?: WithDefault<BackButtonDisplayMode, 'default'>;
hideBackButton?: boolean;
backButtonInCustomView?: boolean;
blurEffect?: WithDefault<BlurEffect, 'extraLight'>;
blurEffect?: WithDefault<BlurEffect, 'none'>;
// TODO: implement this props on iOS
topInsetEnabled?: boolean;
}
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type StackAnimationTypes =
| 'ios_from_right'
| 'ios_from_left';
export type BlurEffectTypes =
| 'none'
| 'extraLight'
| 'light'
| 'dark'
Expand Down
Loading