From 70301ad9f7c56a951e1cf315eaa55b792e9aaa35 Mon Sep 17 00:00:00 2001 From: Christian Baroni <7061887+christianbaroni@users.noreply.github.com> Date: Tue, 17 Sep 2024 21:13:46 -0400 Subject: [PATCH 1/2] Fix iOS 18 cool-modals context menu bug (#6112) --- src/react-native-cool-modals/ios/RNCMScreen.m | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/react-native-cool-modals/ios/RNCMScreen.m b/src/react-native-cool-modals/ios/RNCMScreen.m index fdd546b3143..36598655c64 100644 --- a/src/react-native-cool-modals/ios/RNCMScreen.m +++ b/src/react-native-cool-modals/ios/RNCMScreen.m @@ -9,7 +9,6 @@ // lib #import "Rainbow-Swift.h" - @interface RNCMScreenView () @end @@ -66,7 +65,6 @@ - (void)willDismiss { - (void) setIsShortFormEnabled:(BOOL)isShortFormEnabled { _isShortFormEnabled = isShortFormEnabled; [(PanModalViewController*) [_controller parentVC] panModalSetNeedsLayoutUpdateWrapper]; - } - (void) layout { @@ -83,7 +81,6 @@ - (void) setHidden:(BOOL)hidden { } [(PanModalViewController*) [_controller parentVC] hide]; }); - } } @@ -131,7 +128,6 @@ - (void)updateBounds [_bridge.uiManager setSize:self.bounds.size forView:self]; } - - (void)setPointerEvents:(RCTPointerEvents)pointerEvents { // pointer events settings are managed by the parent screen container, we ignore @@ -335,11 +331,14 @@ - (instancetype)initWithView:(UIView *)view - (void)presentModally:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion slackStack:(BOOL)slackStack { return [_parentVC presentModally:viewControllerToPresent animated:flag completion:completion slackStack:slackStack]; - } - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { - return [_parentVC dismissViewControllerAnimated:flag completion:completion]; + if (self.parentViewController) { + [self.parentViewController dismissViewControllerAnimated:flag completion:completion]; + } else { + [super dismissViewControllerAnimated:flag completion:completion]; + } } - (UIViewController *)presentedViewController { @@ -361,6 +360,16 @@ - (void)viewDidLayoutSubviews } } +- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion { + BOOL isContextMenu = [viewControllerToPresent isKindOfClass:NSClassFromString(@"_UIContextMenuActionsOnlyViewController")]; + + if (isContextMenu) { + [_parentVC presentViewController:viewControllerToPresent animated:flag completion:completion]; + } else { + [super presentViewController:viewControllerToPresent animated:flag completion:completion]; + } +} + - (id)findFirstResponder:(UIView*)parent { if (parent.isFirstResponder) { @@ -426,7 +435,6 @@ @implementation RNCMScreenManager } [(RNCMScreenView *) view jumpTo:point]; }]; - } RCT_EXPORT_METHOD(layout:(nonnull NSNumber*) reactTag) { @@ -438,10 +446,8 @@ @implementation RNCMScreenManager } [(RNCMScreenView *) view layout]; }]; - } - RCT_EXPORT_MODULE() RCT_EXPORT_VIEW_PROPERTY(gestureEnabled, BOOL) @@ -476,7 +482,6 @@ @implementation RNCMScreenManager RCT_EXPORT_VIEW_PROPERTY(ignoreBottomOffset, BOOL) RCT_EXPORT_VIEW_PROPERTY(hidden, BOOL) - - (UIView *)view { return [[RNCMScreenView alloc] initWithBridge:self.bridge]; @@ -494,15 +499,13 @@ @implementation RCTConvert (RNSScreen) @"containedModal": @(RNSScreenStackPresentationContainedModal), @"transparentModal": @(RNSScreenStackPresentationTransparentModal), @"containedTransparentModal": @(RNSScreenStackPresentationContainedTransparentModal) - }), RNSScreenStackPresentationPush, integerValue) +}), RNSScreenStackPresentationPush, integerValue) RCT_ENUM_CONVERTER(RNSScreenStackAnimation, (@{ @"default": @(RNSScreenStackAnimationDefault), @"none": @(RNSScreenStackAnimationNone), @"fade": @(RNSScreenStackAnimationFade), @"flip": @(RNSScreenStackAnimationFlip), - }), RNSScreenStackAnimationDefault, integerValue) - +}), RNSScreenStackAnimationDefault, integerValue) @end - From b836ad85ec7daade6dfd4234b787d28dc55ce2af Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Wed, 18 Sep 2024 18:36:16 -0400 Subject: [PATCH 2/2] Fix send crashes / blank screen (#6116) --- src/hooks/useColorForAsset.ts | 26 +++++++++----------- src/utils/pseudoRandomArrayItemFromString.ts | 4 ++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/hooks/useColorForAsset.ts b/src/hooks/useColorForAsset.ts index 5f497b7fd19..bfaf954e388 100644 --- a/src/hooks/useColorForAsset.ts +++ b/src/hooks/useColorForAsset.ts @@ -1,7 +1,6 @@ import { useMemo } from 'react'; import { lightModeThemeColors } from '../styles/colors'; import { ParsedAddressAsset } from '@/entities'; -import { useTheme } from '@/theme'; import { ethereumUtils, isETH, pseudoRandomArrayItemFromString } from '@/utils'; import { usePersistentDominantColorFromImage } from './usePersistentDominantColorFromImage'; @@ -11,28 +10,27 @@ export default function useColorForAsset( forceLightMode = false, forceETHColor = false ) { + // @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'useTheme'. const { isDarkMode: isDarkModeTheme, colors } = useTheme(); - const accountAsset = ethereumUtils.getAssetFromAllAssets(asset.uniqueId || asset.mainnet_address || asset.address); - const resolvedAddress = asset.mainnet_address || asset.address || accountAsset.address; + const accountAsset = ethereumUtils.getAssetFromAllAssets(asset?.uniqueId || asset?.mainnet_address || asset?.address); + const resolvedAddress = asset?.mainnet_address || asset?.address || accountAsset?.address; const derivedColor = usePersistentDominantColorFromImage(accountAsset?.icon_url || asset?.icon_url); const isDarkMode = forceLightMode || isDarkModeTheme; const colorDerivedFromAddress = useMemo(() => { - if (!isETH(resolvedAddress)) { - return pseudoRandomArrayItemFromString(resolvedAddress, colors.avatarBackgrounds); - } - - if (isDarkMode) { - if (forceETHColor) return colors.appleBlue; - return colors.brighten(lightModeThemeColors.dark); - } - - return colors.dark; + const color = isETH(resolvedAddress) + ? isDarkMode + ? forceETHColor + ? colors.appleBlue + : colors.brighten(lightModeThemeColors.dark) + : colors.dark + : pseudoRandomArrayItemFromString(resolvedAddress, colors.avatarBackgrounds); + return color; }, [colors, forceETHColor, isDarkMode, resolvedAddress]); return useMemo(() => { - let color2Return: string; + let color2Return; // we have special handling for eth color if (isETH(resolvedAddress)) { diff --git a/src/utils/pseudoRandomArrayItemFromString.ts b/src/utils/pseudoRandomArrayItemFromString.ts index fe47a62fb29..050499b7a90 100644 --- a/src/utils/pseudoRandomArrayItemFromString.ts +++ b/src/utils/pseudoRandomArrayItemFromString.ts @@ -1,7 +1,9 @@ const cache: { [key: string]: number } = {}; // For a given string, will always return same item from an array. -export default function pseudoRandomArrayItemFromString(string: string, array: T[]): T { +export default function pseudoRandomArrayItemFromString(string: string, array: T[]): T | null { + if (!string) return null; + if (!cache[string]) { cache[string] = [...string].map(char => char.toLowerCase().charCodeAt(0)).reduce((acc, v) => acc + v, 0); }