react-native-unistyles 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +342 -35
  2. package/lib/commonjs/createUnistyles.js +17 -3
  3. package/lib/commonjs/createUnistyles.js.map +1 -1
  4. package/lib/commonjs/hooks/index.js +13 -0
  5. package/lib/commonjs/hooks/index.js.map +1 -0
  6. package/lib/commonjs/hooks/useDimensions.js +19 -0
  7. package/lib/commonjs/hooks/useDimensions.js.map +1 -0
  8. package/lib/commonjs/hooks/useDimensions.web.js +31 -0
  9. package/lib/commonjs/hooks/useDimensions.web.js.map +1 -0
  10. package/lib/commonjs/utils/styles.js +20 -10
  11. package/lib/commonjs/utils/styles.js.map +1 -1
  12. package/lib/commonjs/utils/styles.spec.js +66 -0
  13. package/lib/commonjs/utils/styles.spec.js.map +1 -1
  14. package/lib/module/createUnistyles.js +17 -3
  15. package/lib/module/createUnistyles.js.map +1 -1
  16. package/lib/module/hooks/index.js +2 -0
  17. package/lib/module/hooks/index.js.map +1 -0
  18. package/lib/module/hooks/useDimensions.js +12 -0
  19. package/lib/module/hooks/useDimensions.js.map +1 -0
  20. package/lib/module/hooks/useDimensions.web.js +24 -0
  21. package/lib/module/hooks/useDimensions.web.js.map +1 -0
  22. package/lib/module/utils/styles.js +20 -10
  23. package/lib/module/utils/styles.js.map +1 -1
  24. package/lib/module/utils/styles.spec.js +66 -0
  25. package/lib/module/utils/styles.spec.js.map +1 -1
  26. package/lib/typescript/src/createUnistyles.d.ts +5 -1
  27. package/lib/typescript/src/createUnistyles.d.ts.map +1 -1
  28. package/lib/typescript/src/hooks/index.d.ts +2 -0
  29. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  30. package/lib/typescript/src/hooks/useDimensions.d.ts +3 -0
  31. package/lib/typescript/src/hooks/useDimensions.d.ts.map +1 -0
  32. package/lib/typescript/src/hooks/useDimensions.web.d.ts +3 -0
  33. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -0
  34. package/lib/typescript/src/types.d.ts +26 -8
  35. package/lib/typescript/src/types.d.ts.map +1 -1
  36. package/lib/typescript/src/utils/styles.d.ts +1 -3
  37. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/createUnistyles.ts +20 -4
  40. package/src/hooks/index.ts +1 -0
  41. package/src/hooks/useDimensions.ts +11 -0
  42. package/src/hooks/useDimensions.web.ts +30 -0
  43. package/src/types.ts +64 -20
  44. package/src/utils/styles.ts +43 -13
package/README.md CHANGED
@@ -28,7 +28,6 @@ Suggestions, ideas, and potential improvements are always welcome!
28
28
 
29
29
  ## Setup
30
30
 
31
-
32
31
  **1. Install library**
33
32
 
34
33
  ```cmd
@@ -39,6 +38,26 @@ yarn add react-native-unistyles
39
38
 
40
39
  You don't have to follow a specific format. Just make an object and add any keys/values you like.
41
40
 
41
+ ```ts
42
+ // theme.ts
43
+ export const theme = {
44
+ colors: {
45
+ blood: '#eb4d4b',
46
+ barbie: '#e056fd',
47
+ pumpkin: '#f0932b',
48
+ background: '#ffffff'
49
+ },
50
+ margins: {
51
+ sm: 2,
52
+ md: 4,
53
+ lg: 8,
54
+ xl: 12
55
+ }
56
+ }
57
+ ```
58
+
59
+ or something more advanced with nested objects / functions:
60
+
42
61
  ```ts
43
62
  // theme.ts
44
63
  export const theme = {
@@ -106,7 +125,7 @@ export const App: React.FunctionComponent = () => (
106
125
  )
107
126
  ```
108
127
 
109
- **5. Access createStyles and useStyles with a factory**
128
+ **5. Access createStyleSheet and useStyles with a factory**
110
129
 
111
130
  ```ts
112
131
  // styles.ts
@@ -119,22 +138,22 @@ import { breakpoints } from './breakpoints'
119
138
  import { theme } from './theme'
120
139
 
121
140
  export const {
122
- createStyles,
141
+ createStyleSheet,
123
142
  useStyles,
124
143
  } = createUnistyles<typeof breakpoints, typeof theme>(breakpoints)
125
144
  ```
126
145
 
127
146
  ## Basic Usage
128
147
 
129
- Library gives you two functions from the factory:
130
- - `createStyles` which replaces `StyleSheet.create`
131
- - `useStyles` which parses your styles based on screen height, width and theme
148
+ After the initial setup, you only need to focus on two functions responsible for your styles:
149
+ - `createStyleSheet` which replaces `StyleSheet.create`
150
+ - `useStyles` which parses your styles and ensures TypeScript compatibility with media queries and breakpoints
132
151
 
133
152
  ```tsx
134
153
  import React from 'react'
135
154
  import { View, Text } from 'react-native'
136
- // access createStyles and useStyles exported from factory
137
- import { createStyles, useStyles } from 'lib/styles'
155
+ // access createStyleSheet and useStyles exported from factory
156
+ import { createStyleSheet, useStyles } from 'lib/styles'
138
157
 
139
158
  export const ExampleUnistyles = () => {
140
159
  const { styles } = useStyles(stylesheet)
@@ -148,7 +167,7 @@ export const ExampleUnistyles = () => {
148
167
  )
149
168
  }
150
169
 
151
- const stylesheet = createStyles(theme => ({
170
+ const stylesheet = createStyleSheet(theme => ({
152
171
  container: {
153
172
  flex: 1,
154
173
  justifyContent: 'center',
@@ -161,24 +180,82 @@ const stylesheet = createStyles(theme => ({
161
180
  }))
162
181
  ```
163
182
 
164
- `createStyles` takes an object like `StyleSheet.create` or function that injects your theme
183
+ ## createStyleSheet
184
+
185
+ `createStyleSheet` is interchangeable with `StyleSheet.create`. You can use objects, and it will function identically to its React Native counterpart.
186
+
187
+ ```ts
188
+ const stylesheet = createStyleSheet({
189
+ container: {
190
+ flex: 1,
191
+ justifyContent: 'center',
192
+ alignItems: 'center',
193
+ },
194
+ })
195
+ ```
196
+ The difference is that you can now use breakpoints and media queries:
197
+
198
+ ```ts
199
+ const stylesheet = createStyleSheet({
200
+ container: {
201
+ flex: 1,
202
+ justifyContent: 'center',
203
+ alignItems: 'center',
204
+ flexDirection: {
205
+ xs: 'row',
206
+ sm: 'column',
207
+ ':w[800]': 'row'
208
+ }
209
+ },
210
+ })
211
+ ```
212
+
213
+ `createStyleSheet` also accepts a function, to which the library will inject your theme:
214
+
215
+ ```ts
216
+ const stylesheet = createStyleSheet(theme => ({
217
+ container: {
218
+ flex: 1,
219
+ justifyContent: 'center',
220
+ alignItems: 'center',
221
+ flexDirection: {
222
+ xs: 'row',
223
+ sm: 'column',
224
+ ':w[800]': 'row'
225
+ },
226
+ backgroundColor: theme.colors.background
227
+ },
228
+ }))
229
+ ```
230
+
231
+ Importantly, you'll receive the same TypeScript hints as with `StyleSheet.create`!
165
232
 
166
- `useStyles` hook takes a `stylesheet` and returns an object with two keys:
167
- - `styles` - parsed styles that can be used directly in React Native components
168
- - `theme` - your app's theme that can be used in JSX
233
+ ## useStyles
169
234
 
170
- You can also skip `stylesheet` if you just want to access `theme`:
235
+ `useStyle` ties everything together and handles the heavy lifting. Without `useStyles`, you can't utilize features like:
236
+ - breakpoints
237
+ - media queries
238
+ - themes
239
+
240
+ _useStyles_ allows you to skip the `stylesheet` if you only want to access the `theme`:
171
241
 
172
242
  ```tsx
173
243
  const { theme } = useStyles()
174
244
  ```
175
245
 
246
+ For more advanced usage, pass your `stylesheet` generated with `createStyleSheet`:
247
+
248
+ ```tsx
249
+ // you can still access theme
250
+ const { styles, theme } = useStyles(stylesheet)
251
+ ```
252
+
176
253
  ## Breakpoints
177
254
 
178
255
  Any style can change based on breakpoints. To do this, change a value to an object:
179
256
 
180
257
  ```ts
181
- const stylesheet = createStyles(theme => ({
258
+ const stylesheet = createStyleSheet(theme => ({
182
259
  container: {
183
260
  flex: 1,
184
261
  justifyContent: 'center',
@@ -195,6 +272,33 @@ const stylesheet = createStyles(theme => ({
195
272
  }))
196
273
  ```
197
274
 
275
+ You can even use it with nested objects like `transform` or `shadowOffset`:
276
+
277
+ ```ts
278
+ const stylesheet = createStyleSheet(theme => ({
279
+ container: {
280
+ flex: 1,
281
+ justifyContent: 'center',
282
+ alignItems: 'center',
283
+ backgroundColor: {
284
+ xs: theme.colors.background,
285
+ sm: theme.colors.barbie
286
+ },
287
+ transform: [
288
+ {
289
+ translateX: 100
290
+ },
291
+ {
292
+ scale: {
293
+ xs: 1.5,
294
+ ':w[500]': 1
295
+ }
296
+ }
297
+ ]
298
+ }
299
+ }))
300
+ ```
301
+
198
302
  Library will choose the correct value (based on screen width) in the runtime.
199
303
 
200
304
  ## Media queries
@@ -211,7 +315,7 @@ For more advanced usage and pixel perfect designs you can also use a custom medi
211
315
  Media queries can be mixed with breakpoints, but have a bigger priority:
212
316
 
213
317
  ```tsx
214
- const stylesheet = createStyles(theme => ({
318
+ const stylesheet = createStyleSheet(theme => ({
215
319
  container: {
216
320
  justifyContent: 'center',
217
321
  alignItems: 'center',
@@ -220,7 +324,8 @@ const stylesheet = createStyles(theme => ({
220
324
  sm: 'row',
221
325
  },
222
326
  backgroundColor: {
223
- xs: theme.colors.background,
327
+ md: theme.colors.background,
328
+ // even though md might overlap with >600px, lib will use 'barbie'
224
329
  ':w[600]': theme.colors.barbie
225
330
  }
226
331
  },
@@ -255,7 +360,7 @@ export const ExampleUnistyles = () => {
255
360
  )
256
361
  }
257
362
 
258
- const stylesheet = createStyles({
363
+ const stylesheet = createStyleSheet({
259
364
  scrollContainer: {
260
365
  flex: 1,
261
366
  justifyContent: 'center',
@@ -267,16 +372,221 @@ const stylesheet = createStyles({
267
372
  })
268
373
  })
269
374
  ```
375
+ If you use a dynamic function, library will wrap it in a `Proxy` to make sure the correct values of breakpoints will be used:
376
+
377
+ ```ts
378
+ const stylesheet = createStyleSheet(theme => ({
379
+ scrollContainer: {
380
+ flex: 1,
381
+ justifyContent: 'center',
382
+ alignItems: 'center',
383
+ },
384
+ post: (index: number) => ({
385
+ // breakpoints and media queries works with dynamic function
386
+ backgroundColor: {
387
+ xs: index % 2 === 0
388
+ ? theme.colors.gold
389
+ : theme.colors.silver,
390
+ sm: theme.colors.red
391
+ }
392
+ })
393
+ }))
394
+ ```
395
+
396
+ ## Dynamic themes
397
+
398
+ You can incorporate as many themes as you desire in your application. While there's flexibility in how you structure your theme, it's essential to maintain consistency with the TypeScript type:
399
+
400
+ To promote reusability and maintainability, it's a good practice to share as many values between themes as possible:
401
+
402
+ ```ts
403
+ // move shared colors to object
404
+ const sharedColors = {
405
+ barbie: '#ff9ff3',
406
+ oak: '#1dd1a1',
407
+ sky: '#48dbfb',
408
+ fog: '#c8d6e5',
409
+ aloes: '#00d2d3'
410
+ }
411
+
412
+ export const lightTheme = {
413
+ colors: {
414
+ // reuse or override them
415
+ ...sharedColors,
416
+ backgroundColor: '#ffffff',
417
+ typography: '#000000'
418
+ }
419
+ // other keys in common with darkTheme
420
+ }
421
+
422
+ export const darkTheme = {
423
+ colors: {
424
+ // reuse or override them
425
+ ...sharedColors,
426
+ backgroundColor: '#000000',
427
+ typography: '#ffffff'
428
+ }
429
+ // other keys in common with lightTheme
430
+ }
431
+
432
+ // export type that will be used to describe your theme
433
+ export type AppTheme = typeof lightTheme | typeof darkTheme
434
+ ```
435
+
436
+ With the themes set up, modify your `createUnistyles` to consume your `AppTheme` type:
437
+
438
+ ```ts
439
+ export const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, AppTheme>(breakpoints)
440
+ ```
441
+
442
+ The final step is to switch your theme based on certain states, persisted values, databases, etc.:
443
+
444
+ ```tsx
445
+ export const App: React.FunctionComponent = () => {
446
+ // obtain here your dark or light theme. It can be storage, state, mmkv, or whateber you use
447
+ // const [yourAppTheme] = useState(lightTheme)
448
+ // const [yourAppTheme] = useYourStorage()
449
+ // const [yourAppTheme] = useMMKVObject<AppTheme>(Theme)
450
+
451
+ // switching theme will re-render your stylesheets automatically
452
+ return (
453
+ <UnistylesTheme theme={yourAppTheme}>
454
+ <Examples.Extreme />
455
+ </UnistylesTheme>
456
+ )
457
+ }
458
+ ```
459
+
460
+ ## Variants
461
+
462
+ `react-native-unistyles` isn't a UI/component library, so you're in charge of designing variants. With no restrictions and using your creativity, you can easily create variants for your components.
463
+
464
+ Let's examine variants for the `Text` component. Imagine you want to create several variants for your `Typography` components:
465
+ - Heading
466
+ - Regular
467
+ - Thin
468
+
469
+ To achieve this, add variants to your theme:
470
+
471
+ ```ts
472
+ export const lightTheme = {
473
+ colors: {
474
+ ...sharedColors,
475
+ backgroundColor: '#ffffff',
476
+ typography: '#000000'
477
+ },
478
+ components: {
479
+ typography: {
480
+ base: {
481
+ fontFamily: 'Roboto',
482
+ fontSize: 12,
483
+ },
484
+ heading: {
485
+ fontFamily: 'Roboto-Medium',
486
+ fontSize: 24,
487
+ },
488
+ regular: {
489
+ fontFamily: 'Roboto',
490
+ fontSize: 12,
491
+ },
492
+ thin: {
493
+ fontFamily: 'Roboto-Thin',
494
+ fontSize: 12,
495
+ },
496
+ bold: {
497
+ fontWeight: 'bold'
498
+ }
499
+ }
500
+ }
501
+ }
502
+ ```
503
+ Next, create a base component:
504
+
505
+ ```tsx
506
+ import React from 'react'
507
+ import type { PropsWithChildren } from 'react'
508
+ import { Text, TextStyle } from 'react-native'
509
+ import { createStyleSheet, useStyles } from 'lib/styles'
510
+
511
+ interface BaseTextProps extends PropsWithChildren {
512
+ bold: boolean,
513
+ style: TextStyle
514
+ }
515
+
516
+ export const BaseText: React.FunctionComponent<BaseTextProps> = ({
517
+ children,
518
+ bold = false,
519
+ style = {}
520
+ }) => {
521
+ const {styles} = useStyles(stylesheet)
522
+
523
+ return (
524
+ <Text
525
+ style={{
526
+ ...styles.baseText,
527
+ ...bold
528
+ ? styles.baseText
529
+ : {},
530
+ // pass other styles via props
531
+ ...style
532
+ }}
533
+ >
534
+ {children}
535
+ </Text>
536
+ )
537
+ }
538
+
539
+ const stylesheet = createStyleSheet(theme => ({
540
+ baseText: {
541
+ ...theme.components.typography.base
542
+ },
543
+ bold: {
544
+ ...theme.components.typography.bold
545
+ }
546
+ }))
547
+ ```
548
+
549
+ Now, let's create another variant, e.g., Heading:
550
+
551
+ ```tsx
552
+ import React from 'react'
553
+ import type { PropsWithChildren } from 'react'
554
+ import { Text, TextStyle } from 'react-native'
555
+ import { createStyleSheet, useStyles } from 'lib/styles'
556
+ import { BaseText } from 'lib/components'
557
+
558
+ interface BaseTextProps extends PropsWithChildren {
559
+ bold: boolean,
560
+ text: string
561
+ }
562
+
563
+ export const Heading: React.FunctionComponent<BaseTextProps> = ({
564
+ text,
565
+ bold = false
566
+ }) => {
567
+ const { theme } = useStyles()
568
+
569
+ return (
570
+ <BaseText
571
+ bold={bold}
572
+ style={theme.components.typography.heading}
573
+ >
574
+ {text}
575
+ </BaseText>
576
+ )
577
+ }
578
+ ```
579
+ And so on...
270
580
 
271
581
  ## Migrate from StyleSheet
272
582
 
273
583
  `react-native-unistyles` embraces the simplicity of `StyleSheet`, making it easy to integrate into your project.
274
584
 
275
- You can replace `StyleSheet.create` with `createStyles` and it will work exactly the same:
585
+ You can replace `StyleSheet.create` with `createStyleSheet` and it will work exactly the same:
276
586
 
277
587
  ```diff
278
588
  -const styles = StyleSheet.create({
279
- +const styles = createStyles({
589
+ +const styles = createStyleSheet({
280
590
  scrollContainer: {
281
591
  flex: 1,
282
592
  justifyContent: 'center',
@@ -294,21 +604,7 @@ export const ExampleUnistyles = () => {
294
604
  }
295
605
  ```
296
606
 
297
- With the hook in place, you can now use `breakpoints` and `media-queries`.
298
-
299
- Additionally, to access the `theme` use a function instead of an `object`:
300
-
301
- ```diff
302
- -const stylesheet = createStyles({
303
- +const stylesheet = createStyles(theme => ({
304
- scrollContainer: {
305
- flex: 1,
306
- justifyContent: 'center',
307
- alignItems: 'center',
308
- backgroundColor: theme.colors.background
309
- }
310
- }))
311
- ```
607
+ With the hook in place, you can now use all the features.
312
608
 
313
609
  ## Example
314
610
 
@@ -318,6 +614,17 @@ In order to check out working example go to [example/](./example).
318
614
 
319
615
  For more detailed explanation please refer to my blog post [here](https://www.reactnativecrossroads.com/posts/level-up-react-native-styles).
320
616
 
617
+
618
+ ## Sponsor my work
619
+
620
+ If you found the `react-native-unistyles` time-saving and valuable, please consider sponsoring my work. Your support enables me to continue creating libraries with a fresh approach.
621
+
622
+ Github: https://github.com/sponsors/jpudysz
623
+
624
+ Ko-fi: https://ko-fi.com/jpudysz
625
+
626
+ Your support is greatly appreciated and helps me dedicate more time and resources to creating quality libraries. Thank you for all the support!
627
+
321
628
  ## License
322
629
 
323
630
  MIT
@@ -5,16 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createUnistyles = void 0;
7
7
  var _react = require("react");
8
- var _reactNative = require("react-native");
9
8
  var _UnistylesTheme = require("./UnistylesTheme");
10
9
  var _utils = require("./utils");
10
+ var _hooks = require("./hooks");
11
11
  const createUnistyles = breakpoints => {
12
12
  const sortedBreakpoints = (0, _utils.sortAndValidateBreakpoints)(breakpoints);
13
13
  return {
14
- createStyles: styles => styles,
14
+ /**
15
+ * @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
16
+ */
17
+ createStyles: styles => {
18
+ if (typeof styles === 'function') {
19
+ return styles;
20
+ }
21
+ return styles;
22
+ },
23
+ createStyleSheet: styles => {
24
+ if (typeof styles === 'function') {
25
+ return styles;
26
+ }
27
+ return styles;
28
+ },
15
29
  useStyles: stylesheet => {
16
30
  const theme = (0, _react.useContext)(_UnistylesTheme.UnistylesContext);
17
- const dimensions = (0, _reactNative.useWindowDimensions)();
31
+ const dimensions = (0, _hooks.useDimensions)();
18
32
  const breakpoint = (0, _utils.getBreakpointFromScreenWidth)(dimensions.width, sortedBreakpoints);
19
33
  const screenSize = {
20
34
  width: dimensions.width,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_reactNative","_UnistylesTheme","_utils","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useWindowDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OA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ACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHM,KAAK;QACLH,MAAM,EAAEc;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAA9B,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_react","require","_UnistylesTheme","_utils","_hooks","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","createStyleSheet","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAG,IAAAC,iCAA0B,EAACF,WAAW,CAAC;EAEjE,OAAO;IACH;AACR;AACA;IACQG,YAAY,EAAyCC,MAAqF,IAAY;MAClJ,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;QAC9B,OAAOA,MAAM;MACjB;MAEA,OAAOA,MAAM;IACjB,CAAC;IACDC,gBAAgB,EAAyCD,MAAqF,IAAY;MACtJ,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;QAC9B,OAAOA,MAAM;MACjB;MAEA,OAAOA,MAAM;IACjB,CAAC;IACDE,SAAS,EAAwCC,UAA4C,IAAK;MAC9F,MAAMC,KAAK,GAAG,IAAAC,iBAAU,EAACC,gCAAgB,CAAM;MAC/C,MAAMC,UAAU,GAAG,IAAAC,oBAAa,EAAC,CAAC;MAClC,MAAMC,UAAU,GAAG,IAAAC,mCAA4B,EAAIH,UAAU,CAACI,KAAK,EAAEd,iBAAiB,CAAC;MACvF,MAAMe,UAAsB,GAAG;QAC3BD,KAAK,EAAEJ,UAAU,CAACI,KAAK;QACvBE,MAAM,EAAEN,UAAU,CAACM;MACvB,CAAC;MAED,IAAI,CAACV,UAAU,EAAE;QACb,OAAO;UACHC,KAAK;UACLJ,MAAM,EAAE,CAAC;QACb,CAAC;MACL;MAEA,MAAMc,YAAY,GAAG,OAAOX,UAAU,KAAK,UAAU,GAC/CA,UAAU,CAACC,KAAK,CAAC,GACjBD,UAAU;MAEhB,MAAMY,iBAAiB,GAAGC,MAAM,CAC3BC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QACtB,MAAMG,CAAC,GAAGD,KAAiC;QAE3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAAIF,KAAK,EAAEb,UAAU,EAAEG,UAAU,EAAEf,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGsB,GAAG;UACN,CAACE,GAAG,GAAG,IAAAI,iBAAU,EAAQF,CAAC,EAAEd,UAAU,EAAEG,UAAU,EAAEf,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHO,KAAK;QACLJ,MAAM,EAAEe;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAA/B,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useDimensions", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useDimensions.useDimensions;
10
+ }
11
+ });
12
+ var _useDimensions = require("./useDimensions");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_useDimensions","require"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDimensions = void 0;
7
+ var _reactNative = require("react-native");
8
+ const useDimensions = () => {
9
+ const {
10
+ width,
11
+ height
12
+ } = (0, _reactNative.useWindowDimensions)();
13
+ return {
14
+ width,
15
+ height
16
+ };
17
+ };
18
+ exports.useDimensions = useDimensions;
19
+ //# sourceMappingURL=useDimensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","useDimensions","width","height","useWindowDimensions","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,gCAAmB,EAAC,CAAC;EAE/C,OAAO;IACHF,KAAK;IACLC;EACJ,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAJ,aAAA,GAAAA,aAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDimensions = void 0;
7
+ var _react = require("react");
8
+ const useDimensions = () => {
9
+ const timerRef = (0, _react.useRef)();
10
+ const [screenSize, setScreenSize] = (0, _react.useState)({
11
+ width: window.innerWidth,
12
+ height: window.innerHeight
13
+ });
14
+ (0, _react.useEffect)(() => {
15
+ const handleResize = () => {
16
+ clearTimeout(timerRef.current);
17
+ timerRef.current = setTimeout(() => setScreenSize({
18
+ width: window.innerWidth,
19
+ height: window.innerHeight
20
+ }), 100);
21
+ };
22
+ window.addEventListener('resize', handleResize);
23
+ return () => {
24
+ window.removeEventListener('resize', handleResize);
25
+ clearTimeout(timerRef.current);
26
+ };
27
+ }, []);
28
+ return screenSize;
29
+ };
30
+ exports.useDimensions = useDimensions;
31
+ //# sourceMappingURL=useDimensions.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","width","window","innerWidth","height","innerHeight","useEffect","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa;IACrDC,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;MAE9Bb,QAAQ,CAACa,OAAO,GAAGC,UAAU,CAAC,MAAMX,aAAa,CAAC;QAC9CE,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACS,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTL,MAAM,CAACU,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOX,UAAU;AACrB,CAAC;AAAAe,OAAA,CAAAlB,aAAA,GAAAA,aAAA"}
@@ -56,15 +56,25 @@ const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => new Proxy(f
56
56
  * // { fontSize: '12px' }
57
57
  */
58
58
  exports.proxifyFunction = proxifyFunction;
59
- const parseStyle = (style, breakpoint, screenSize, breakpoints) => Object.fromEntries(Object.entries(style).map(_ref => {
60
- let [key, value] = _ref;
61
- const isDynamicFunction = typeof value === 'function';
62
- const isValidStyle = typeof value !== 'object' || key === 'transform';
63
- if (isDynamicFunction || isValidStyle) {
64
- return [key, value];
65
- }
66
- const valueWithBreakpoint = value;
67
- return [key, (0, _breakpoints.getValueForBreakpoint)(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
68
- }));
59
+ const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
60
+ const entries = Object.entries(style);
61
+ return Object.fromEntries(entries.map(_ref => {
62
+ let [key, value] = _ref;
63
+ const isNestedStyle = key === 'shadowOffset';
64
+ if (isNestedStyle) {
65
+ return [key, parseStyle(value, breakpoint, screenSize, breakpoints)];
66
+ }
67
+ const isTransform = key === 'transform';
68
+ if (isTransform && Array.isArray(value)) {
69
+ return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))];
70
+ }
71
+ const isDynamicFunction = typeof value === 'function';
72
+ const isValidStyle = typeof value !== 'object';
73
+ if (isDynamicFunction || isValidStyle) {
74
+ return [key, value];
75
+ }
76
+ return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize, breakpoints)];
77
+ }));
78
+ };
69
79
  exports.parseStyle = parseStyle;
70
80
  //# sourceMappingURL=styles.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","Object","fromEntries","entries","map","_ref","key","value","isDynamicFunction","isValidStyle","valueWithBreakpoint","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA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GAAAA,UAAA"}
1
+ {"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEP,UAAU,EAAEC,UAAU,EAAEC,WAAW;AAC5F,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBAO,OAAA,CAAAX,eAAA,GAAAA,eAAA;AAyBO,MAAMU,UAAU,GAAGA,CACtBE,KAA8B,EAC9BV,UAA4B,EAC5BC,UAAsB,EACtBC,WAAc,KACV;EACJ,MAAMS,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACD,KAAK,CAGnC;EAED,OAAOE,MAAM,CACRC,WAAW,CAACF,OAAO,CACfG,GAAG,CAACC,IAAA,IAAkB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACd,MAAMG,aAAa,GAAGF,GAAG,KAAK,cAAc;IAE5C,IAAIE,aAAa,EAAE;MACf,OAAO,CACHF,GAAG,EAC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