-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: resolve RN 0.85 web warnings and upgrade Expo SDK 56 #4958
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import React from 'react'; | ||
| import { Animated } from 'react-native'; | ||
| import { Animated, Platform, StyleSheet } from 'react-native'; | ||
|
|
||
| import { act } from '@testing-library/react-native'; | ||
| import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock'; | ||
|
|
@@ -44,6 +44,35 @@ describe('Appbar', () => { | |
|
|
||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('uses boxShadow instead of shadow props on web headers', () => { | ||
| const originalPlatform = Platform.OS; | ||
| Platform.OS = 'web'; | ||
|
|
||
| try { | ||
| const { getByTestId } = render( | ||
| <mockSafeAreaContext.SafeAreaProvider> | ||
| <Appbar.Header elevated> | ||
| <Appbar.Content title="Examples" /> | ||
| </Appbar.Header> | ||
| </mockSafeAreaContext.SafeAreaProvider> | ||
| ); | ||
|
|
||
| const styles = StyleSheet.flatten( | ||
| getByTestId('appbar-header-root-layer').props.style | ||
| ); | ||
|
|
||
| expect(styles).toMatchObject({ | ||
| boxShadow: '0px 2px 6px rgba(0, 0, 0, 0.3)', | ||
| }); | ||
| expect(styles).not.toHaveProperty('shadowColor'); | ||
| expect(styles).not.toHaveProperty('shadowOpacity'); | ||
| expect(styles).not.toHaveProperty('shadowOffset'); | ||
| expect(styles).not.toHaveProperty('shadowRadius'); | ||
| } finally { | ||
| Platform.OS = originalPlatform; | ||
| } | ||
| }); | ||
|
Comment on lines
+48
to
+75
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this test. Tests shouldn't test implementation details. To test for deprecated styles an appropriate test would be to actually check whether there are console warnings. Though I think that's not really necessary. |
||
| }); | ||
|
|
||
| describe('renderAppbarContent', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import React from 'react'; | ||
| import { Image } from 'react-native'; | ||
| import { Image, StyleSheet } from 'react-native'; | ||
|
|
||
| import { render } from '../../test-utils'; | ||
| import Icon from '../Icon'; | ||
|
|
@@ -18,6 +18,26 @@ describe('Icon Component', () => { | |
| expect(imageIcon).toHaveStyle({ width: ICON_SIZE, height: ICON_SIZE }); | ||
| }); | ||
|
|
||
| it('passes image-specific props without using deprecated style keys', () => { | ||
| const tintColor = 'tomato'; | ||
| const source = { uri: 'https://picsum.photos/700' }; | ||
| const { getByTestId } = render( | ||
| <Icon | ||
| source={source} | ||
| size={ICON_SIZE} | ||
| color={tintColor} | ||
| testID="image-icon" | ||
| /> | ||
| ); | ||
| const imageIcon = getByTestId('image-icon'); | ||
| const styles = StyleSheet.flatten(imageIcon.props.style); | ||
|
|
||
| expect(imageIcon.props.resizeMode).toBe('contain'); | ||
| expect(imageIcon.props.tintColor).toBe(tintColor); | ||
| expect(styles).not.toHaveProperty('resizeMode'); | ||
| expect(styles).not.toHaveProperty('tintColor'); | ||
| }); | ||
|
Comment on lines
+21
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this test |
||
|
|
||
| it('renders correctly with string source', () => { | ||
| const source = 'camera'; | ||
| const { getByTestId } = render( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,33 @@ describe('Surface', () => { | |
| expect(getByTestId(testID).props.pointerEvents).toBe('box-none'); | ||
| }); | ||
|
|
||
| it('renders web shadows with boxShadow instead of shadow props', () => { | ||
| const originalPlatform = Platform.OS; | ||
| Platform.OS = 'web'; | ||
|
|
||
| try { | ||
| const { getByTestId } = render( | ||
| <Surface elevation={5} testID="surface-test"> | ||
| {null} | ||
| </Surface> | ||
| ); | ||
|
|
||
| const styles = StyleSheet.flatten( | ||
| getByTestId('surface-test').props.style | ||
| ); | ||
|
|
||
| expect(styles).toMatchObject({ | ||
| boxShadow: '0px 8px 12px rgba(0, 0, 0, 0.3)', | ||
| }); | ||
| expect(styles).not.toHaveProperty('shadowColor'); | ||
| expect(styles).not.toHaveProperty('shadowOpacity'); | ||
| expect(styles).not.toHaveProperty('shadowOffset'); | ||
| expect(styles).not.toHaveProperty('shadowRadius'); | ||
| } finally { | ||
| Platform.OS = originalPlatform; | ||
| } | ||
|
Comment on lines
+20
to
+44
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this test. |
||
| }); | ||
|
|
||
| describe('on iOS', () => { | ||
| Platform.OS = 'ios'; | ||
| const styles = StyleSheet.create({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| // M3 elevation tokens and shadow builder per spec: | ||
| // https://m3.material.io/styles/elevation/tokens | ||
|
|
||
| import { Animated, type ColorValue } from 'react-native'; | ||
| import { Animated, Platform, type ColorValue } from 'react-native'; | ||
|
|
||
| import color from 'color'; | ||
|
|
||
| import { isAnimatedValue } from '../../../utils/animations'; | ||
| import type { Elevation, ThemeElevation } from '../../types'; | ||
|
|
@@ -32,10 +34,38 @@ export const shadowLayers = [ | |
| }, | ||
| ]; | ||
|
|
||
| const getShadowColor = (shadowColor: ColorValue, shadowOpacity: number) => | ||
| color(typeof shadowColor === 'string' ? shadowColor : 'black') | ||
| .alpha(shadowOpacity) | ||
| .rgb() | ||
| .string(); | ||
|
Comment on lines
+37
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a non-string is received on Web, it should throw an error as it's a user error instead of defaulting to black. |
||
|
|
||
| const getBoxShadowValue = (elevation: number, shadowColor: ColorValue) => | ||
| `0px ${shadowLayers[0].height[elevation]}px ${ | ||
| shadowLayers[0].shadowRadius[elevation] | ||
| }px ${getShadowColor(shadowColor, elevation ? 0.3 : 0)}`; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for interpolations, this is doing color manipulation multiple times even though the color is not changing. Move this to the web branch and assign it to a variable, then reuse the variable in the shadow. |
||
|
|
||
| export function shadow( | ||
| elevation: number | Animated.Value = 0, | ||
| shadowColor: ColorValue | ||
| ) { | ||
| if (Platform.OS === 'web') { | ||
| if (isAnimatedValue(elevation)) { | ||
| return { | ||
| boxShadow: elevation.interpolate({ | ||
| inputRange: elevationInputRange, | ||
| outputRange: elevationInputRange.map((value) => | ||
| getBoxShadowValue(value, shadowColor) | ||
| ), | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| boxShadow: getBoxShadowValue(elevation, shadowColor), | ||
| }; | ||
| } | ||
|
|
||
| if (isAnimatedValue(elevation)) { | ||
| return { | ||
| shadowColor, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you seeing warnings about
tintColor? I only see warnings forresizeModeandshadow*