@@ -208,48 +208,73 @@ export class RN {
208208 }
209209
210210 if ( typeof value === 'object' ) {
211- const properties = Object . keys ( value )
212- // border properties are border{X}Color instead of borderColor{X}
213- const propertyEnd = property . includes ( 'border' )
214- ? property . split ( 'border' ) . at ( - 1 ) ?? ''
215- : ''
216- const transformedProperty = property . replace ( propertyEnd , '' )
217-
218- if ( properties . every ( property => [ 'row' , 'column' ] . includes ( property ) ) ) {
219- return {
220- rowGap : value . row ,
221- columnGap : value . column ,
222- }
211+ const transformed = this . transformObjectProperty ( property , value )
212+
213+ if ( transformed ) {
214+ return transformed
223215 }
216+ }
224217
225- if ( properties . every ( property => [ 'start' , 'end' ] . includes ( property ) ) ) {
226- return {
227- [ `${ transformedProperty } Start${ propertyEnd } ` ] : value . start ,
228- [ `${ transformedProperty } End${ propertyEnd } ` ] : value . end ,
229- }
218+ return {
219+ [ property ] : value ,
220+ }
221+ }
222+
223+ private transformObjectProperty ( property : string , value : Record < string , any > ) {
224+ const properties = Object . keys ( value )
225+ // border properties are border{X}Color instead of borderColor{X}
226+ const propertyEnd = property . includes ( 'border' )
227+ ? property . split ( 'border' ) . at ( - 1 ) ?? ''
228+ : ''
229+ const transformedProperty = property . replace ( propertyEnd , '' )
230+ const isSpacing = property . includes ( 'margin' ) || property . includes ( 'padding' )
231+
232+ const wrapProperty = ( prop : string ) => `${ transformedProperty } ${ prop } ${ propertyEnd } `
233+
234+ if ( properties . every ( property => [ 'row' , 'column' ] . includes ( property ) ) ) {
235+ return {
236+ rowGap : value . row ,
237+ columnGap : value . column ,
230238 }
239+ }
231240
232- if ( properties . every ( property => [ 'top' , 'right' , 'bottom' , 'left' ] . includes ( property ) ) ) {
241+ if ( properties . every ( property => [ 'start' , 'end' ] . includes ( property ) ) ) {
242+ if ( isSpacing && property . includes ( 'Horizontal' ) ) {
233243 return {
234- [ `${ transformedProperty } Top${ propertyEnd } ` ] : value . top ,
235- [ `${ transformedProperty } Right${ propertyEnd } ` ] : value . right ,
236- [ `${ transformedProperty } Bottom${ propertyEnd } ` ] : value . bottom ,
237- [ `${ transformedProperty } Left${ propertyEnd } ` ] : value . left ,
244+ [ `${ property . replace ( 'Horizontal' , 'Left' ) } ` ] : value . start ,
245+ [ `${ property . replace ( 'Horizontal' , 'Right' ) } ` ] : value . end ,
238246 }
239247 }
240248
241- if ( properties . every ( property => [ 'topLeft' , 'topRight' , 'bottomRight' , 'bottomLeft' ] . includes ( property ) ) ) {
249+ if ( isSpacing && property . includes ( 'Vertical' ) ) {
242250 return {
243- [ `${ transformedProperty } TopLeft${ propertyEnd } ` ] : value . topLeft ,
244- [ `${ transformedProperty } TopRight${ propertyEnd } ` ] : value . topRight ,
245- [ `${ transformedProperty } BottomRight${ propertyEnd } ` ] : value . bottomRight ,
246- [ `${ transformedProperty } BottomLeft${ propertyEnd } ` ] : value . bottomLeft ,
251+ [ `${ property . replace ( 'Vertical' , 'Top' ) } ` ] : value . start ,
252+ [ `${ property . replace ( 'Vertical' , 'Bottom' ) } ` ] : value . end ,
247253 }
248254 }
255+
256+ return {
257+ [ wrapProperty ( 'Start' ) ] : value . start ,
258+ [ wrapProperty ( 'End' ) ] : value . end ,
259+ }
249260 }
250261
251- return {
252- [ property ] : value ,
262+ if ( properties . every ( property => [ 'top' , 'right' , 'bottom' , 'left' ] . includes ( property ) ) ) {
263+ return {
264+ [ wrapProperty ( 'Top' ) ] : value . top ,
265+ [ wrapProperty ( 'Right' ) ] : value . right ,
266+ [ wrapProperty ( 'Bottom' ) ] : value . bottom ,
267+ [ wrapProperty ( 'Left' ) ] : value . left ,
268+ }
269+ }
270+
271+ if ( properties . every ( property => [ 'topLeft' , 'topRight' , 'bottomRight' , 'bottomLeft' ] . includes ( property ) ) ) {
272+ return {
273+ [ wrapProperty ( 'TopLeft' ) ] : value . topLeft ,
274+ [ wrapProperty ( 'TopRight' ) ] : value . topRight ,
275+ [ wrapProperty ( 'BottomRight' ) ] : value . bottomRight ,
276+ [ wrapProperty ( 'BottomLeft' ) ] : value . bottomLeft ,
277+ }
253278 }
254279 }
255280}
0 commit comments