Skip to content

Commit c85d44a

Browse files
authored
Merge pull request #326 from jpudysz/feature/new-props
feat: add support for new rn 0.76 css props
2 parents 65e858f + 02d9471 commit c85d44a

File tree

8 files changed

+950
-1835
lines changed

8 files changed

+950
-1835
lines changed

examples/bare/src/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const App: React.FunctionComponent = () => {
2828
>
2929
<Text>Switch theme</Text>
3030
</Pressable>
31+
<View style={styles.box} />
3132
</View>
3233
)
3334
}
@@ -65,5 +66,20 @@ const stylesheet = createStyleSheet((theme, rt) => ({
6566
},
6667
bold: {
6768
fontWeight: 'bold'
69+
},
70+
box: {
71+
height: 100,
72+
width: 100,
73+
position: 'absolute',
74+
backgroundColor: theme.colors.fog,
75+
filter: [
76+
{
77+
brightness: 0.2
78+
},
79+
{
80+
opacity: 0.5
81+
}
82+
],
83+
boxShadow: '0 0 10 10 rgba(255, 0, 0, 0.5)'
6884
}
6985
}))

examples/tv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"expo": "51.0.14",
1515
"expo-build-properties": "0.12.3",
1616
"react": "18.3.1",
17-
"react-native": "npm:react-native-tvos@~0.74.2-0"
17+
"react-native": "npm:react-native-tvos@latest"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "7.24.7",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"jest": "29.7.0",
8787
"metro-react-native-babel-preset": "0.77.0",
8888
"react": "18.3.1",
89-
"react-native": "0.74.2",
89+
"react-native": "0.76.0",
9090
"react-native-builder-bob": "0.23.2",
9191
"react-native-web": "0.19.12",
9292
"react-test-renderer": "18.3.1",

src/__tests__/styles.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe('styles', () => {
163163
}
164164

165165
const parsedStyles = parseStyle(
166-
style as StyleSheet,
166+
style as unknown as StyleSheet,
167167
{}
168168
)
169169

src/types/normalizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ShadowStyleIOS, TextStyle, TransformsStyle } from 'react-native'
22

3-
type TransformArrayElement<T> = T extends Array<infer U> ? U : never
3+
type TransformArrayElement<T> = T extends ReadonlyArray<infer U> ? U : never
44
type BoxShadow = Required<ShadowStyleIOS>
55
type TextShadow = Required<Pick<TextStyle, 'textShadowColor' | 'textShadowOffset' | 'textShadowRadius'>>
66
type Transforms = Array<TransformArrayElement<TransformsStyle['transform']>>

src/types/stylesheet.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
1+
import type { BoxShadowValue, FilterFunction, ImageStyle, TextStyle, ViewStyle } from 'react-native'
22
import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
33
import type { UnistylesBreakpoints } from '../global'
44
import type { UnistylesMiniRuntime } from '../core'
55

66
// these props are treated differently to nest breakpoints and media queries
7-
type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
7+
type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset' | 'boxShadow' | 'filter'
88

99
export type UnistyleView = Omit<ViewStyle, NestedKeys>
1010
export type UnistyleText = Omit<TextStyle, NestedKeys>
@@ -13,7 +13,9 @@ export type UnistyleImage = Omit<ImageStyle, NestedKeys>
1313
type UnistyleNestedStyles = {
1414
shadowOffset?: ToDeepUnistyles<ShadowOffset>,
1515
textShadowOffset?: ToDeepUnistyles<ShadowOffset>,
16-
transform?: Array<ToDeepUnistyles<TransformStyles>>
16+
transform?: Array<ToDeepUnistyles<TransformStyles>>,
17+
boxShadow?: Array<ToDeepUnistyles<BoxShadowValue>> | string,
18+
filter?: Array<ToDeepUnistyles<FilterFunction>> | string
1719
}
1820

1921
type Variants = {

src/utils/styles.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export const parseStyle = <T extends RNStyle>(
4949
return acc
5050
}
5151

52+
if ((key === 'boxShadow' || key === 'filter') && Array.isArray(value)) {
53+
acc[key] = value
54+
.map(value => parseStyle(value, variant, false))
55+
.filter(value => Object.keys(value).length === 1)
56+
57+
return acc
58+
}
59+
5260
if (key === 'fontVariant' && Array.isArray(value)) {
5361
acc[key] = value
5462

0 commit comments

Comments
 (0)