@codeandmoney/soelma 0.0.0-dev.0 → 0.0.0-dev.1
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.
- package/DefaultTheme.d.ts +2 -0
- package/DefaultTheme.js +1 -0
- package/appearance/consts.d.ts +1 -0
- package/appearance/index.d.ts +8 -0
- package/appearance/index.js +18 -0
- package/appearance/init.d.ts +1 -0
- package/{src/appearance/init.ts → appearance/init.js} +1 -6
- package/context.d.ts +4 -0
- package/context.js +3 -0
- package/createEventEmitter.d.ts +8 -0
- package/createEventEmitter.js +11 -0
- package/dark-mode/consts.d.ts +1 -0
- package/dark-mode/index.d.ts +7 -0
- package/dark-mode/index.js +16 -0
- package/dark-mode/init.d.ts +1 -0
- package/dark-mode/init.js +13 -0
- package/dark-mode/state.d.ts +3 -0
- package/{src/dark-mode/state.ts → dark-mode/state.js} +1 -2
- package/dependencyRegistry.d.ts +5 -0
- package/dependencyRegistry.js +12 -0
- package/dependencyUsage.d.ts +7 -0
- package/dependencyUsage.js +10 -0
- package/dimensions/consts.d.ts +2 -0
- package/dimensions/index.d.ts +4 -0
- package/dimensions/index.js +13 -0
- package/dimensions/init.d.ts +1 -0
- package/dimensions/init.js +21 -0
- package/dimensions/utils.d.ts +1 -0
- package/dimensions/utils.js +7 -0
- package/i18n.d.ts +7 -0
- package/i18n.js +9 -0
- package/index.js +5 -0
- package/{src/makeUseStyles → makeUseStyles}/index.d.ts +1 -1
- package/{src/makeUseStyles → makeUseStyles}/utils.js +4 -4
- package/media-query/base.d.ts +12 -0
- package/media-query/base.js +18 -0
- package/media-query/breakpoints.d.ts +18 -0
- package/media-query/breakpoints.js +60 -0
- package/media-query/index.d.ts +2 -0
- package/media-query/index.js +2 -0
- package/orientation.d.ts +7 -0
- package/orientation.js +7 -0
- package/package.json +6 -37
- package/safe-area/SafeAreaProvider.d.ts +3 -0
- package/safe-area/SafeAreaProvider.js +9 -0
- package/safe-area/StylexSaveAreaConsumer.d.ts +2 -0
- package/safe-area/StylexSaveAreaConsumer.js +15 -0
- package/safe-area/consts.d.ts +1 -0
- package/safe-area/eventEmitter.d.ts +1 -0
- package/{src/safe-area/eventEmitter.ts → safe-area/eventEmitter.js} +0 -1
- package/safe-area/index.d.ts +5 -0
- package/{src/safe-area/index.tsx → safe-area/index.js} +3 -9
- package/safe-area/init.d.ts +1 -0
- package/{src/safe-area/init.tsx → safe-area/init.js} +1 -3
- package/safe-area/state.d.ts +8 -0
- package/{src/safe-area/state.ts → safe-area/state.js} +5 -7
- package/safe-area/types.d.ts +9 -0
- package/safe-area/types.js +1 -0
- package/useColorTransition.d.ts +5 -0
- package/useColorTransition.js +38 -0
- package/useTheme.d.ts +2 -0
- package/useTheme.js +9 -0
- package/withStyles.d.ts +7 -0
- package/withStyles.js +13 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -31
- package/.github/workflows/nodejs.yml +0 -33
- package/.size-limit.json +0 -6
- package/babel.config.js +0 -3
- package/docs/api.md +0 -103
- package/docs/appearance.md +0 -54
- package/docs/dark-mode.md +0 -46
- package/docs/dimensions.md +0 -29
- package/docs/i18n.md +0 -67
- package/docs/logo.png +0 -0
- package/docs/media-query.md +0 -274
- package/docs/orientation.md +0 -44
- package/docs/safe-area.md +0 -62
- package/docs/testting.md +0 -51
- package/docs/ts.md +0 -127
- package/example/AppStyleX/.watchmanconfig +0 -1
- package/example/AppStyleX/android/build.gradle +0 -26
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/example/AppStyleX/android/gradle.properties +0 -53
- package/example/AppStyleX/android/gradlew +0 -249
- package/example/AppStyleX/android/gradlew.bat +0 -92
- package/example/AppStyleX/android/settings.gradle +0 -12
- package/example/AppStyleX/app.json +0 -28
- package/example/AppStyleX/babel.config.js +0 -3
- package/example/AppStyleX/index.js +0 -9
- package/example/AppStyleX/ios/Podfile +0 -7
- package/example/AppStyleX/ios/Podfile.lock +0 -1252
- package/example/AppStyleX/metro.config.js +0 -54
- package/example/AppStyleX/package.json +0 -43
- package/example/AppStyleX/react-native.config.js +0 -23
- package/example/AppStyleX/src/App.tsx +0 -25
- package/example/AppStyleX/src/BottomNav/index.tsx +0 -32
- package/example/AppStyleX/src/BottomNav/styles.ts +0 -42
- package/example/AppStyleX/src/Circle/index.tsx +0 -53
- package/example/AppStyleX/src/Circle/styles.ts +0 -22
- package/example/AppStyleX/src/Root/index.tsx +0 -41
- package/example/AppStyleX/src/Root/styles.ts +0 -18
- package/example/AppStyleX/src/ToggleButton/index.tsx +0 -66
- package/example/AppStyleX/src/ToggleButton/styles.ts +0 -69
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +0 -5
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +0 -5
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +0 -8
- package/example/AppStyleX/src/style-system/palette.ts +0 -11
- package/example/AppStyleX/src/style-system/theme.ts +0 -14
- package/example/AppStyleX/src/style-system/utils.ts +0 -11
- package/example/AppStyleX/src/stylex.d.ts +0 -6
- package/example/AppStyleX/tsconfig.json +0 -3
- package/example/AppStyleX/yarn.lock +0 -6767
- package/jest.config.js +0 -19
- package/src/DefaultTheme.ts +0 -4
- package/src/__tests__/createBreakpoints.test.ts +0 -152
- package/src/__tests__/createBreakpointsMatcher.test.ts +0 -188
- package/src/__tests__/createBreakpointsMatcher.types-test.ts +0 -81
- package/src/__tests__/createEventEmitter.test.ts +0 -37
- package/src/__tests__/dark-mode.test.ts +0 -56
- package/src/__tests__/dependencyRegistry.test.ts +0 -16
- package/src/__tests__/dependencyUsage.test.ts +0 -13
- package/src/__tests__/dimensions.test.ts +0 -36
- package/src/__tests__/makeUseStyles.types-test.ts +0 -69
- package/src/__tests__/media-query.test.ts +0 -204
- package/src/__tests__/orientation.test.ts +0 -61
- package/src/__tests__/useTheme.test.ts +0 -26
- package/src/__tests__/withStyles.types-test.tsx +0 -173
- package/src/appearance/index.ts +0 -37
- package/src/context.ts +0 -9
- package/src/createEventEmitter.ts +0 -26
- package/src/dark-mode/index.ts +0 -29
- package/src/dark-mode/init.ts +0 -19
- package/src/dependencyRegistry.ts +0 -21
- package/src/dependencyUsage.ts +0 -31
- package/src/dimensions/index.ts +0 -20
- package/src/dimensions/init.ts +0 -37
- package/src/dimensions/utils.ts +0 -11
- package/src/i18n.ts +0 -18
- package/src/makeUseStyles/createUseStylesTheme.test.js +0 -137
- package/src/makeUseStyles/createUseStylesWithoutTheme.test.js +0 -63
- package/src/makeUseStyles/index.test.js +0 -28
- package/src/media-query/base.ts +0 -43
- package/src/media-query/breakpoints.ts +0 -121
- package/src/media-query/index.ts +0 -12
- package/src/orientation.ts +0 -17
- package/src/safe-area/SafeAreaProvider.tsx +0 -17
- package/src/safe-area/StylexSaveAreaConsumer.ts +0 -23
- package/src/safe-area/types.ts +0 -10
- package/src/useColorTransition.ts +0 -50
- package/src/useTheme.ts +0 -16
- package/src/withStyles.tsx +0 -35
- package/tsconfig.json +0 -30
- /package/{src/appearance/consts.ts → appearance/consts.js} +0 -0
- /package/{src/dark-mode/consts.ts → dark-mode/consts.js} +0 -0
- /package/{src/dimensions/consts.ts → dimensions/consts.js} +0 -0
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/createUseStylesTheme.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/createUseStylesWithoutTheme.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/index.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/test-type.js +0 -0
- /package/{src/safe-area/consts.ts → safe-area/consts.js} +0 -0
package/docs/media-query.md
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
# Media Query support 💉
|
|
2
|
-
|
|
3
|
-
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
4
|
-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
5
|
-
|
|
6
|
-
- [High level api](#high-level-api)
|
|
7
|
-
- [`createBreakpoints(breakpoints)`](#createbreakpointsbreakpoints)
|
|
8
|
-
- [`createBreakpointsMatcher(breakpoints, matcherFunction)`](#createbreakpointsmatcherbreakpoints-matcherfunction)
|
|
9
|
-
- [Inject into theme](#inject-into-theme)
|
|
10
|
-
- [Core media conditions:](#core-media-conditions)
|
|
11
|
-
- [`maxWidth(width: number, {/* styles */})`](#maxwidthwidth-number--styles-)
|
|
12
|
-
- [`minWidth(width: number, {/* styles */})`](#minwidthwidth-number--styles-)
|
|
13
|
-
- [`maxHeight(height: number, {/* styles */})`](#maxheightheight-number--styles-)
|
|
14
|
-
- [`minHeight(height: number, {/* styles */})`](#minheightheight-number--styles-)
|
|
15
|
-
- [`aspectRatio(ratio: number, {/* styles */})`](#aspectratioratio-number--styles-)
|
|
16
|
-
- [`maxAspectRatio(ratio: number, {/* styles */})`](#maxaspectratioratio-number--styles-)
|
|
17
|
-
- [`minAspectRatio(ratio: number, {/* styles */})`](#minaspectratioratio-number--styles-)
|
|
18
|
-
|
|
19
|
-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
20
|
-
|
|
21
|
-
## High level api
|
|
22
|
-
|
|
23
|
-
#### `createBreakpoints(breakpoints)`
|
|
24
|
-
|
|
25
|
-
Media queries are the idiomatic approach to make your UI responsive.
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { createBreakpoints } from "react-native-stylex/media-query";
|
|
29
|
-
|
|
30
|
-
const config = {
|
|
31
|
-
sm: 600,
|
|
32
|
-
md: 960,
|
|
33
|
-
lg: 1280,
|
|
34
|
-
xl: 1920,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const breakpoints = createBreakpoints(config);
|
|
38
|
-
|
|
39
|
-
breakpoints.up("sm", value);
|
|
40
|
-
breakpoints.down("md", value);
|
|
41
|
-
breakpoints.only("lg", value);
|
|
42
|
-
breakpoints.between("sm", "lg", value);
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
- `breakpoints.down<T>(key: string, value: T): T | null`
|
|
46
|
-
|
|
47
|
-
A media query matches screen widths less than and including the screen size given by the breakpoint key.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
makeUseStyles(() => ({
|
|
51
|
-
text: {
|
|
52
|
-
fontSize: 16,
|
|
53
|
-
|
|
54
|
-
// Match: [0, sm, md, lg] xl, ∞
|
|
55
|
-
// [0........1280]
|
|
56
|
-
...breakpoints.down("lg", { fontSize: 18 }),
|
|
57
|
-
|
|
58
|
-
// Match: [0, sm] md, lg, xl, ∞
|
|
59
|
-
// [0...600]
|
|
60
|
-
...breakpoints.down("sm", { fontSize: 20 }),
|
|
61
|
-
},
|
|
62
|
-
}));
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
- `breakpoints.up<T>(key: string, value: T): T | null`
|
|
66
|
-
A media query which matches screen widths greater than and including the screen size given by the breakpoint key.
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
makeUseStyles(() => ({
|
|
70
|
-
text: {
|
|
71
|
-
fontSize: 20,
|
|
72
|
-
|
|
73
|
-
// Match: 0, [sm, md, lg, xl, ∞]
|
|
74
|
-
// [600.............∞]
|
|
75
|
-
...breakpoints.up("sm", { fontSize: 18 }),
|
|
76
|
-
|
|
77
|
-
// Match: 0, sm, md, [lg, xl, ∞]
|
|
78
|
-
// [1280....∞]
|
|
79
|
-
...breakpoints.up("lg", { fontSize: 16 }),
|
|
80
|
-
},
|
|
81
|
-
}));
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
- `breakpoints.only<T>(key: string, value: T): T | null`
|
|
85
|
-
A media query which matches screen widths including the screen size given by the breakpoint key.
|
|
86
|
-
|
|
87
|
-
```ts
|
|
88
|
-
makeUseStyles(() => ({
|
|
89
|
-
text: {
|
|
90
|
-
fontSize: 16,
|
|
91
|
-
|
|
92
|
-
// Match: 0, sm, [md, lg], xl, ∞
|
|
93
|
-
// [960...1280]
|
|
94
|
-
...breakpoints.only("md", { fontSize: 20 }),
|
|
95
|
-
},
|
|
96
|
-
}));
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
- `breakpoints.between<T>(start: string, end: string, value: T): T | null`
|
|
100
|
-
A media query which matches screen widths greater than the screen width given by the breakpoint key in the first argument and less than the screen width given by the breakpoint key in the second argument
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
makeUseStyles(() => ({
|
|
104
|
-
text: {
|
|
105
|
-
fontSize: 16,
|
|
106
|
-
|
|
107
|
-
// Match: 0, [sm, md, lg], xl, ∞
|
|
108
|
-
// [600...1280]
|
|
109
|
-
...breakpoints.between("sm", "lg", { fontSize: 20 }),
|
|
110
|
-
},
|
|
111
|
-
}));
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
#### `createBreakpointsMatcher(breakpoints, matcherFunction)`
|
|
117
|
-
|
|
118
|
-
- `breakpoints: { [key: string]: number }` - object where keys have string type and values positive number
|
|
119
|
-
- `matcherFunction: ` - optional, (by default `minWidth`). One of the media query matcher function (maxAspectRatio, maxHeight, maxWidth, minAspectRatio, minHeight, minWidth)
|
|
120
|
-
|
|
121
|
-
To easily **understand** and **debug** you can use a [CSS analog](https://codepen.io/retyui/pen/dyOzKzV) of implementation `createBreakpointsMatcher` ([video preview...](https://user-images.githubusercontent.com/4661784/108605405-92456780-73bc-11eb-9ec1-eb2e765c4164.mp4))
|
|
122
|
-
|
|
123
|
-
**Example:**
|
|
124
|
-
|
|
125
|
-
```tsx
|
|
126
|
-
import {
|
|
127
|
-
createBreakpointsMatcher,
|
|
128
|
-
maxHeight,
|
|
129
|
-
maxWidth,
|
|
130
|
-
minHeight,
|
|
131
|
-
minWidth,
|
|
132
|
-
minAspectRatio,
|
|
133
|
-
maxAspectRatio,
|
|
134
|
-
} from "react-native-stylex/media-query";
|
|
135
|
-
|
|
136
|
-
const applyBreakpoints = createBreakpointsMatcher(
|
|
137
|
-
{
|
|
138
|
-
// breakpoints config
|
|
139
|
-
xxs: 320,
|
|
140
|
-
xs: 480,
|
|
141
|
-
s: 640,
|
|
142
|
-
m: 768,
|
|
143
|
-
l: 1024,
|
|
144
|
-
xl: 1200,
|
|
145
|
-
xxl: 1920,
|
|
146
|
-
},
|
|
147
|
-
matcherFunction // Optional matcher function (be default 'minWidth')
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
/*
|
|
151
|
-
* ⚠ Pay attention that result of this function depends on the passed matcher function (mix\max)!
|
|
152
|
-
* ⬇️ See below to understand a difference ⬇️
|
|
153
|
-
*/
|
|
154
|
-
const useStyles = makeUseStyles(() => ({
|
|
155
|
-
text: {
|
|
156
|
-
// !!! ⚠ WHEN 'matcherFunction' is 'maxWidth' ⚠ !!!
|
|
157
|
-
// if window width 0....320 => fontSize: 20
|
|
158
|
-
// if window width 321..480 => fontSize: 18
|
|
159
|
-
// if window width 481... => fontSize: 16
|
|
160
|
-
fontSize: applyBreakpoints({
|
|
161
|
-
default: 16,
|
|
162
|
-
xs: 18,
|
|
163
|
-
xxs: 20,
|
|
164
|
-
}),
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
title: {
|
|
168
|
-
// !!! ⚠ WHEN 'matcherFunction' is 'minWidth' ⚠ !!!
|
|
169
|
-
// if window width 0....319 => fontSize: 20
|
|
170
|
-
// if window width 320..479 => fontSize: 18
|
|
171
|
-
// if window width 480.. => fontSize: 16
|
|
172
|
-
fontSize: applyBreakpoints({
|
|
173
|
-
xs: 16,
|
|
174
|
-
xxs: 18,
|
|
175
|
-
default: 20,
|
|
176
|
-
}),
|
|
177
|
-
},
|
|
178
|
-
}));
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
#### Inject into theme
|
|
182
|
-
|
|
183
|
-
> ⚠️ Note: I recommend you to add created breakpoints functions to your theme, and use them directly without importing
|
|
184
|
-
|
|
185
|
-
**Example:**
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
// theme.ts
|
|
189
|
-
const config = { sm: 360, md: 600 /*...*/ };
|
|
190
|
-
const breakpoints = createBreakpoints(config);
|
|
191
|
-
const applyBreakpoints = createBreakpointsMatcher(config, matcherFunction);
|
|
192
|
-
|
|
193
|
-
const theme = {
|
|
194
|
-
pallete: { white: "#fff" /*...*/ },
|
|
195
|
-
breakpoints,
|
|
196
|
-
applyBreakpoints,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// -----------------------------------------------
|
|
200
|
-
// styles.ts
|
|
201
|
-
const useStyles = makeUseStyles(({ applyBreakpoints }) => ({
|
|
202
|
-
root: {
|
|
203
|
-
fontSize: utils.applyBreakpoints({
|
|
204
|
-
xxs: 20,
|
|
205
|
-
xs: 18,
|
|
206
|
-
default: 16,
|
|
207
|
-
}),
|
|
208
|
-
},
|
|
209
|
-
}));
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
---
|
|
213
|
-
|
|
214
|
-
## Core media conditions:
|
|
215
|
-
|
|
216
|
-
#### `maxWidth(width: number, {/* styles */})`
|
|
217
|
-
|
|
218
|
-
Return styles when a window width is equal or less than passed `width`
|
|
219
|
-
|
|
220
|
-
#### `minWidth(width: number, {/* styles */})`
|
|
221
|
-
|
|
222
|
-
Return styles when a window width is equal or greater than passed `width`
|
|
223
|
-
|
|
224
|
-
#### `maxHeight(height: number, {/* styles */})`
|
|
225
|
-
|
|
226
|
-
Return styles when window height is equal or less than passed `height`
|
|
227
|
-
|
|
228
|
-
#### `minHeight(height: number, {/* styles */})`
|
|
229
|
-
|
|
230
|
-
Return styles when window height is equal or greater than passed `height`
|
|
231
|
-
|
|
232
|
-
#### `aspectRatio(ratio: number, {/* styles */})`
|
|
233
|
-
|
|
234
|
-
Return styles when a window aspect ratio is the same as a passed `ratio`
|
|
235
|
-
|
|
236
|
-
#### `maxAspectRatio(ratio: number, {/* styles */})`
|
|
237
|
-
|
|
238
|
-
Return styles when a window aspect ratio is equal or less than passed `ratio`
|
|
239
|
-
|
|
240
|
-
#### `minAspectRatio(ratio: number, {/* styles */})`
|
|
241
|
-
|
|
242
|
-
Return styles when a window aspect ratio is equal or greater than passed `ratio`
|
|
243
|
-
|
|
244
|
-
**Example:**
|
|
245
|
-
|
|
246
|
-
```js
|
|
247
|
-
import { makeUseStyles } from "react-native-stylex";
|
|
248
|
-
import { minWidth } from "react-native-stylex/media-query";
|
|
249
|
-
|
|
250
|
-
const useStyles = makeUseStyles(() => ({
|
|
251
|
-
root: {
|
|
252
|
-
// default styles
|
|
253
|
-
height: 200,
|
|
254
|
-
width: 200,
|
|
255
|
-
|
|
256
|
-
...minWidth(320, {
|
|
257
|
-
// if window width MORE then 320 apply next stylex
|
|
258
|
-
height: 160,
|
|
259
|
-
width: 160,
|
|
260
|
-
}),
|
|
261
|
-
},
|
|
262
|
-
panel: {
|
|
263
|
-
// default styles
|
|
264
|
-
height: 200,
|
|
265
|
-
width: 200,
|
|
266
|
-
|
|
267
|
-
...maxWidth(320, {
|
|
268
|
-
// if window width LESS then 320 apply next stylex
|
|
269
|
-
height: 160,
|
|
270
|
-
width: 160,
|
|
271
|
-
}),
|
|
272
|
-
},
|
|
273
|
-
}));
|
|
274
|
-
```
|
package/docs/orientation.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Orientation 📲
|
|
2
|
-
|
|
3
|
-
#### `orientation({ portrait, landscape })`
|
|
4
|
-
|
|
5
|
-
This function given an object containing orientation variants as keys, returns the value for the orientation you are
|
|
6
|
-
currently. (inspired by [`Platform.select(...)`](https://facebook.github.io/reac-native/docs/platform-specific-code#platform-module))
|
|
7
|
-
|
|
8
|
-
#### `portraitOrientation(value)`
|
|
9
|
-
|
|
10
|
-
Return passed value when device in portrait orientation
|
|
11
|
-
|
|
12
|
-
#### `landscapeOrientation(value)`
|
|
13
|
-
|
|
14
|
-
Return passed value when device in landscape orientation
|
|
15
|
-
|
|
16
|
-
**Example:**
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
import { makeUseStyles } from "react-native-stylex";
|
|
20
|
-
import {
|
|
21
|
-
orientation,
|
|
22
|
-
portraitOrientation,
|
|
23
|
-
landscapeOrientation,
|
|
24
|
-
} from "react-native-stylex/orientation";
|
|
25
|
-
|
|
26
|
-
const useStyles = makeUseStyles(() => ({
|
|
27
|
-
cell: {
|
|
28
|
-
backgroundColor: "red",
|
|
29
|
-
...orientation({
|
|
30
|
-
portrait: { alignSelf: "flex-start" },
|
|
31
|
-
landscape: { alignSelf: "flex-end" },
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
row: {
|
|
35
|
-
width: portraitOrientation(100),
|
|
36
|
-
},
|
|
37
|
-
root: {
|
|
38
|
-
...landscapeOrientation({
|
|
39
|
-
top: 10,
|
|
40
|
-
left: 10,
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
}));
|
|
44
|
-
```
|
package/docs/safe-area.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# 🛡️ Safe area
|
|
2
|
-
|
|
3
|
-
It is really useful for fixed elements on screen
|
|
4
|
-
|
|
5
|
-
<img src="https://cdn.dribbble.com/users/261602/screenshots/5947654/bottom_search.png" width="500" />
|
|
6
|
-
|
|
7
|
-
To start using integration with [react-native-safe-area-context](https://github.com/th3rdwave/react-native-safe-area-context) module
|
|
8
|
-
|
|
9
|
-
You need install it using [instructions](https://github.com/th3rdwave/react-native-safe-area-context#getting-started)!
|
|
10
|
-
|
|
11
|
-
Then you need to render `<StylexSaveAreaConsumer/>` inside `SafeAreaProvider`.
|
|
12
|
-
|
|
13
|
-
```jsx
|
|
14
|
-
import React, { useState } from "react";
|
|
15
|
-
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
16
|
-
import { StylexSaveAreaConsumer } from "react-native-stylex/safe-area";
|
|
17
|
-
|
|
18
|
-
import App from "./App";
|
|
19
|
-
|
|
20
|
-
const Root = () => {
|
|
21
|
-
return (
|
|
22
|
-
<SafeAreaProvider>
|
|
23
|
-
<App />
|
|
24
|
-
<StylexSaveAreaConsumer />
|
|
25
|
-
</SafeAreaProvider>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Or you can use custom `SafeAreaProvider` from stylex
|
|
31
|
-
|
|
32
|
-
```jsx
|
|
33
|
-
import React, { useState } from "react";
|
|
34
|
-
import { SafeAreaProvider } from "react-native-stylex/safe-area";
|
|
35
|
-
|
|
36
|
-
import App from "./App";
|
|
37
|
-
|
|
38
|
-
const Root = () => {
|
|
39
|
-
return (
|
|
40
|
-
<SafeAreaProvider>
|
|
41
|
-
<App />
|
|
42
|
-
</SafeAreaProvider>
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
After that you can use `getSafeArea()` method to get edge insets
|
|
48
|
-
|
|
49
|
-
**Example:**
|
|
50
|
-
|
|
51
|
-
```jsx
|
|
52
|
-
import { makeUseStyles } from "react-native-stylex";
|
|
53
|
-
import { getSafeArea } from "react-native-stylex/safe-area";
|
|
54
|
-
|
|
55
|
-
export const useStyles = makeUseStyles(() => ({
|
|
56
|
-
fixedButton: {
|
|
57
|
-
position: "absolute",
|
|
58
|
-
start: 20,
|
|
59
|
-
bottom: 30 + getSafeArea().bottom,
|
|
60
|
-
},
|
|
61
|
-
}));
|
|
62
|
-
```
|
package/docs/testting.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Writing tests 📝
|
|
2
|
-
|
|
3
|
-
## Using [Jest](https://jestjs.io/) for testing?
|
|
4
|
-
|
|
5
|
-
You should just use `<Provider>` and manually pass theme as a prop to every component that use `useStyles()` in unit tests
|
|
6
|
-
|
|
7
|
-
**./testing.js**
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import React from "react";
|
|
11
|
-
import { ThemeProvider } from "react-native-stylex";
|
|
12
|
-
|
|
13
|
-
import { defaultTheme } from "./my-theme";
|
|
14
|
-
|
|
15
|
-
export const MockThemeProvider = (props) => (
|
|
16
|
-
<ThemeProvider {...props} value={defaultTheme} />
|
|
17
|
-
);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
**./MyComponent.text.js**
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
import React from "react";
|
|
24
|
-
import TestRenderer from "react-test-renderer";
|
|
25
|
-
import { MockThemeProvider } from "./testing";
|
|
26
|
-
import MyComponent from "./MyComponent";
|
|
27
|
-
|
|
28
|
-
const testRenderer = TestRenderer.create(
|
|
29
|
-
<MockThemeProvider>
|
|
30
|
-
<MyComponent />
|
|
31
|
-
</MockThemeProvider>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
//...
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Troubleshooting
|
|
38
|
-
|
|
39
|
-
### **`SyntaxError: Unexpected token export\import` in react-native-stylex/...**
|
|
40
|
-
|
|
41
|
-
You need to point Jest to transform this package. You can do so, by adding module path to `transformIgnorePatterns` setting in Jest's configuration.
|
|
42
|
-
|
|
43
|
-
```json
|
|
44
|
-
{
|
|
45
|
-
"jest": {
|
|
46
|
-
"transformIgnorePatterns": [
|
|
47
|
-
'node_modules/(?!((jest-)?react-native|react-native-stylex|@react-native(-community)?)/)',
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
package/docs/ts.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# Typescript support ⛱️
|
|
2
|
-
|
|
3
|
-
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
4
|
-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
5
|
-
|
|
6
|
-
- [DefaultTheme](#defaulttheme)
|
|
7
|
-
- [`withStyles()` HoC](#withstyles-hoc)
|
|
8
|
-
|
|
9
|
-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
10
|
-
|
|
11
|
-
### DefaultTheme
|
|
12
|
-
|
|
13
|
-
TypeScript definitions for stylex can be extended by using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) since version `v4.1.4` of the definitions.
|
|
14
|
-
|
|
15
|
-
So the first step is creating a declarations file. Let's name it `stylex.d.ts` for example.
|
|
16
|
-
|
|
17
|
-
**./theme.ts**
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
export const theme = {
|
|
21
|
-
colors: { textColor: "black" },
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type MyTheme = typeof theme;
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**./stylex.d.ts**
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import "react-native-stylex";
|
|
31
|
-
import type { MyTheme } from "./theme";
|
|
32
|
-
|
|
33
|
-
declare module "react-native-stylex" {
|
|
34
|
-
export interface DefaultTheme extends MyTheme {}
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
`DefaultTheme` is being used as an interface of `makeUseStyles(theme => ...)` out of the box.
|
|
39
|
-
|
|
40
|
-
By default, the interface DefaultTheme is empty so that's why we need to extend it.
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
### `withStyles()` HoC
|
|
45
|
-
|
|
46
|
-
To make life developer easy was added helper type `InferInjectedStyledProps<TFunc>`
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
const useStyles2 = makeUseStyles(() => ({
|
|
50
|
-
cell: { width: 10 },
|
|
51
|
-
root: { color: "red" },
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
// {
|
|
55
|
-
// styles: {
|
|
56
|
-
// root: {...},
|
|
57
|
-
// cell: {...}
|
|
58
|
-
// }
|
|
59
|
-
// } <==> InferInjectedStyledProps<typeof useStyles>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
So final result should be looks like that:
|
|
63
|
-
|
|
64
|
-
**Example:**
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import React, { Ref, forwardRef } from "react";
|
|
68
|
-
import { TextInput } from "react-native";
|
|
69
|
-
import {
|
|
70
|
-
makeUseStyles,
|
|
71
|
-
withStyles,
|
|
72
|
-
InferInjectedStyledProps,
|
|
73
|
-
} from "react-native-stylex";
|
|
74
|
-
|
|
75
|
-
const useStyles = makeUseStyles(() => ({
|
|
76
|
-
root: {
|
|
77
|
-
color: "red",
|
|
78
|
-
},
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
interface Props extends InferInjectedStyledProps<typeof useStyles> {
|
|
82
|
-
value?: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function MyComponent(props: Props) {
|
|
86
|
-
return <TextInput style={props.styles.root} value={props.value} />;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const Styled = withStyles(useStyles)(MyComponent);
|
|
90
|
-
|
|
91
|
-
<Styled
|
|
92
|
-
value="str"
|
|
93
|
-
// @ts-expect-error: 'styles' Already injected
|
|
94
|
-
styles={{}}
|
|
95
|
-
/>;
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
> ⚠️ Ref support by default!
|
|
99
|
-
|
|
100
|
-
In `4.x.x` version was improved type detection for 'ref'
|
|
101
|
-
|
|
102
|
-
it works well with class and functional components
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
const MyFnc = forwardRef<TextInput, Props>((props, ref) => (
|
|
106
|
-
<TextInput ref={ref} style={props.styles.root} />
|
|
107
|
-
));
|
|
108
|
-
|
|
109
|
-
class MyTextInput extends React.Component<Props> {
|
|
110
|
-
scrollTo() {}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const StyledCls = withStyles(useStyles)(MyTextInput);
|
|
114
|
-
const StyledFnc = withStyles(useStyles)(MyFnc);
|
|
115
|
-
|
|
116
|
-
<StyledCls
|
|
117
|
-
ref={(instance) => {
|
|
118
|
-
instance?.scrollTo();
|
|
119
|
-
}}
|
|
120
|
-
/>;
|
|
121
|
-
|
|
122
|
-
<StyledFnc
|
|
123
|
-
ref={(instance) => {
|
|
124
|
-
instance?.blur();
|
|
125
|
-
}}
|
|
126
|
-
/>;
|
|
127
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
buildscript {
|
|
2
|
-
def androidTestAppDir = "../node_modules/react-native-test-app/android"
|
|
3
|
-
apply(from: "${androidTestAppDir}/dependencies.gradle")
|
|
4
|
-
|
|
5
|
-
repositories {
|
|
6
|
-
mavenCentral()
|
|
7
|
-
google()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
dependencies {
|
|
11
|
-
getReactNativeDependencies().each { dependency ->
|
|
12
|
-
classpath(dependency)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
allprojects {
|
|
18
|
-
repositories {
|
|
19
|
-
maven {
|
|
20
|
-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
21
|
-
url("${rootDir}/../node_modules/react-native/android")
|
|
22
|
-
}
|
|
23
|
-
mavenCentral()
|
|
24
|
-
google()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
Binary file
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Project-wide Gradle settings.
|
|
2
|
-
|
|
3
|
-
# IDE (e.g. Android Studio) users:
|
|
4
|
-
# Gradle settings configured through the IDE *will override*
|
|
5
|
-
# any settings specified in this file.
|
|
6
|
-
|
|
7
|
-
# For more details on how to configure your build environment visit
|
|
8
|
-
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
9
|
-
|
|
10
|
-
# Specifies the JVM arguments used for the Gradle Daemon. The setting is
|
|
11
|
-
# particularly useful for configuring JVM memory settings for build performance.
|
|
12
|
-
# This does not affect the JVM settings for the Gradle client VM.
|
|
13
|
-
# The default is `-Xmx512m -XX:MaxMetaspaceSize=256m`.
|
|
14
|
-
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
15
|
-
|
|
16
|
-
# When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute
|
|
17
|
-
# projects in parallel. To learn more about parallel task execution, see the
|
|
18
|
-
# section on Gradle build performance:
|
|
19
|
-
# https://docs.gradle.org/current/userguide/performance.html#parallel_execution.
|
|
20
|
-
# Default is `false`.
|
|
21
|
-
#org.gradle.parallel=true
|
|
22
|
-
|
|
23
|
-
# AndroidX package structure to make it clearer which packages are bundled with the
|
|
24
|
-
# Android operating system, and which are packaged with your app's APK
|
|
25
|
-
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
|
26
|
-
android.useAndroidX=true
|
|
27
|
-
# Automatically convert third-party libraries to use AndroidX
|
|
28
|
-
android.enableJetifier=true
|
|
29
|
-
# Jetifier randomly fails on these libraries
|
|
30
|
-
android.jetifier.ignorelist=hermes-android
|
|
31
|
-
|
|
32
|
-
# Version of Flipper to use with React Native. Default value is whatever React
|
|
33
|
-
# Native defaults to. To enable Flipper, set the value to `X.Y.Z` (version you want to use).
|
|
34
|
-
# To disable Flipper, set it to `false`.
|
|
35
|
-
FLIPPER_VERSION=false
|
|
36
|
-
|
|
37
|
-
# Use this property to specify which architecture you want to build.
|
|
38
|
-
# You can also override it from the CLI using
|
|
39
|
-
# ./gradlew <task> -PreactNativeArchitectures=x86_64
|
|
40
|
-
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
|
|
41
|
-
|
|
42
|
-
# Enable Fabric at runtime.
|
|
43
|
-
#USE_FABRIC=1
|
|
44
|
-
|
|
45
|
-
# Enable new architecture, i.e. Fabric + TurboModule - implies USE_FABRIC=1.
|
|
46
|
-
# Note that this is incompatible with web debugging.
|
|
47
|
-
#newArchEnabled=true
|
|
48
|
-
|
|
49
|
-
# Uncomment the line below if building react-native from source
|
|
50
|
-
#ANDROID_NDK_VERSION=23.1.7779620
|
|
51
|
-
|
|
52
|
-
# Version of Kotlin to build against.
|
|
53
|
-
#KOTLIN_VERSION=1.7.22
|