File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ const staticDeclarations = new WeakMap<
32
32
33
33
const extraRules = new WeakMap < StyleRule , Partial < StyleRule > [ ] > ( ) ;
34
34
35
+ const keywords = new Set ( [ "unset" ] ) ;
36
+
35
37
export class StylesheetBuilder {
36
38
animationFrames ?: AnimationKeyframes_V2 [ ] ;
37
39
animationDeclarations : StyleDeclaration [ ] = [ ] ;
@@ -418,6 +420,8 @@ export class StylesheetBuilder {
418
420
] ) ;
419
421
} else if ( Array . isArray ( value ) && value . some ( isStyleFunction ) ) {
420
422
declarations . push ( [ value , propPath ] ) ;
423
+ } else if ( typeof value === "string" && keywords . has ( value ) ) {
424
+ declarations . push ( [ value , propPath ] ) ;
421
425
} else {
422
426
let staticDeclarationRecord = staticDeclarations . get ( declarations ) ;
423
427
if ( ! staticDeclarationRecord ) {
Original file line number Diff line number Diff line change
1
+ import { View } from "react-native" ;
2
+
3
+ import { renderHook } from "@testing-library/react-native" ;
4
+ import { registerCSS } from "react-native-css/jest" ;
5
+
6
+ import { useNativeCss } from "../react/useNativeCss" ;
7
+
8
+ test ( "unset" , ( ) => {
9
+ registerCSS ( `.my-class { background-color: unset; }` ) ;
10
+
11
+ const { result } = renderHook ( ( ) => {
12
+ return useNativeCss ( View , { className : "my-class" } ) ;
13
+ } ) ;
14
+
15
+ expect ( result . current . props ) . toStrictEqual ( {
16
+ style : { backgroundColor : undefined } ,
17
+ } ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change @@ -116,10 +116,16 @@ export function resolveValue(
116
116
case "number" :
117
117
case "boolean" :
118
118
return value ;
119
- case "string" :
120
- return value . endsWith ( "px" ) // Inline vars() might set a value with a px suffix
121
- ? parseInt ( value . slice ( 0 , - 2 ) , 10 )
122
- : value ;
119
+ case "string" : {
120
+ if ( value === "unset" ) {
121
+ return null ;
122
+ } else if ( value . endsWith ( "px" ) ) {
123
+ // Inline vars() might set a value with a px suffix
124
+ return parseInt ( value . slice ( 0 , - 2 ) , 10 ) ;
125
+ } else {
126
+ return value ;
127
+ }
128
+ }
123
129
case "object" : {
124
130
if ( ! Array . isArray ( value ) ) {
125
131
return value ;
Original file line number Diff line number Diff line change @@ -49,8 +49,13 @@ export function applyValue(
49
49
prop : string ,
50
50
value : any ,
51
51
) {
52
+ // This is confusing.
53
+ // An undefined value means "don't set anything" (something failed while parsing)
54
+ // While a null value means "remove this value", which in React Native means "set to undefined"
52
55
if ( value === undefined ) {
53
56
return ;
57
+ } else if ( value === null ) {
58
+ value = undefined ;
54
59
}
55
60
56
61
if ( transformKeys . has ( prop ) ) {
You can’t perform that action at this time.
0 commit comments