@codeandmoney/soelma 0.0.0-dev.0
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/.eslintignore +1 -0
- package/.eslintrc.js +31 -0
- package/.github/workflows/nodejs.yml +33 -0
- package/.size-limit.json +6 -0
- package/CHANGELOG.md +90 -0
- package/LICENSE +21 -0
- package/README.md +169 -0
- package/babel.config.js +3 -0
- package/docs/api.md +103 -0
- package/docs/appearance.md +54 -0
- package/docs/dark-mode.md +46 -0
- package/docs/dimensions.md +29 -0
- package/docs/i18n.md +67 -0
- package/docs/logo.png +0 -0
- package/docs/media-query.md +274 -0
- package/docs/orientation.md +44 -0
- package/docs/safe-area.md +62 -0
- package/docs/testting.md +51 -0
- package/docs/ts.md +127 -0
- package/example/AppStyleX/.watchmanconfig +1 -0
- package/example/AppStyleX/android/build.gradle +26 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/example/AppStyleX/android/gradle.properties +53 -0
- package/example/AppStyleX/android/gradlew +249 -0
- package/example/AppStyleX/android/gradlew.bat +92 -0
- package/example/AppStyleX/android/settings.gradle +12 -0
- package/example/AppStyleX/app.json +28 -0
- package/example/AppStyleX/babel.config.js +3 -0
- package/example/AppStyleX/index.js +9 -0
- package/example/AppStyleX/ios/Podfile +7 -0
- package/example/AppStyleX/ios/Podfile.lock +1252 -0
- package/example/AppStyleX/metro.config.js +54 -0
- package/example/AppStyleX/package.json +43 -0
- package/example/AppStyleX/react-native.config.js +23 -0
- package/example/AppStyleX/src/App.tsx +25 -0
- package/example/AppStyleX/src/BottomNav/index.tsx +32 -0
- package/example/AppStyleX/src/BottomNav/styles.ts +42 -0
- package/example/AppStyleX/src/Circle/index.tsx +53 -0
- package/example/AppStyleX/src/Circle/styles.ts +22 -0
- package/example/AppStyleX/src/Root/index.tsx +41 -0
- package/example/AppStyleX/src/Root/styles.ts +18 -0
- package/example/AppStyleX/src/ToggleButton/index.tsx +66 -0
- package/example/AppStyleX/src/ToggleButton/styles.ts +69 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +8 -0
- package/example/AppStyleX/src/style-system/palette.ts +11 -0
- package/example/AppStyleX/src/style-system/theme.ts +14 -0
- package/example/AppStyleX/src/style-system/utils.ts +11 -0
- package/example/AppStyleX/src/stylex.d.ts +6 -0
- package/example/AppStyleX/tsconfig.json +3 -0
- package/example/AppStyleX/yarn.lock +6767 -0
- package/jest.config.js +19 -0
- package/package.json +59 -0
- package/src/DefaultTheme.ts +4 -0
- package/src/__tests__/createBreakpoints.test.ts +152 -0
- package/src/__tests__/createBreakpointsMatcher.test.ts +188 -0
- package/src/__tests__/createBreakpointsMatcher.types-test.ts +81 -0
- package/src/__tests__/createEventEmitter.test.ts +37 -0
- package/src/__tests__/dark-mode.test.ts +56 -0
- package/src/__tests__/dependencyRegistry.test.ts +16 -0
- package/src/__tests__/dependencyUsage.test.ts +13 -0
- package/src/__tests__/dimensions.test.ts +36 -0
- package/src/__tests__/makeUseStyles.types-test.ts +69 -0
- package/src/__tests__/media-query.test.ts +204 -0
- package/src/__tests__/orientation.test.ts +61 -0
- package/src/__tests__/useTheme.test.ts +26 -0
- package/src/__tests__/withStyles.types-test.tsx +173 -0
- package/src/appearance/consts.ts +1 -0
- package/src/appearance/index.ts +37 -0
- package/src/appearance/init.ts +12 -0
- package/src/context.ts +9 -0
- package/src/createEventEmitter.ts +26 -0
- package/src/dark-mode/consts.ts +1 -0
- package/src/dark-mode/index.ts +29 -0
- package/src/dark-mode/init.ts +19 -0
- package/src/dark-mode/state.ts +5 -0
- package/src/dependencyRegistry.ts +21 -0
- package/src/dependencyUsage.ts +31 -0
- package/src/dimensions/consts.ts +2 -0
- package/src/dimensions/index.ts +20 -0
- package/src/dimensions/init.ts +37 -0
- package/src/dimensions/utils.ts +11 -0
- package/src/i18n.ts +18 -0
- package/src/index.ts +7 -0
- package/src/makeUseStyles/createUseStylesTheme.js +42 -0
- package/src/makeUseStyles/createUseStylesTheme.test.js +137 -0
- package/src/makeUseStyles/createUseStylesWithoutTheme.js +38 -0
- package/src/makeUseStyles/createUseStylesWithoutTheme.test.js +63 -0
- package/src/makeUseStyles/index.d.ts +7 -0
- package/src/makeUseStyles/index.js +12 -0
- package/src/makeUseStyles/index.test.js +28 -0
- package/src/makeUseStyles/test-type.js +28 -0
- package/src/makeUseStyles/utils.js +67 -0
- package/src/media-query/base.ts +43 -0
- package/src/media-query/breakpoints.ts +121 -0
- package/src/media-query/index.ts +12 -0
- package/src/orientation.ts +17 -0
- package/src/safe-area/SafeAreaProvider.tsx +17 -0
- package/src/safe-area/StylexSaveAreaConsumer.ts +23 -0
- package/src/safe-area/consts.ts +1 -0
- package/src/safe-area/eventEmitter.ts +4 -0
- package/src/safe-area/index.tsx +16 -0
- package/src/safe-area/init.tsx +6 -0
- package/src/safe-area/state.ts +12 -0
- package/src/safe-area/types.ts +10 -0
- package/src/useColorTransition.ts +50 -0
- package/src/useTheme.ts +16 -0
- package/src/withStyles.tsx +35 -0
- package/tsconfig.json +30 -0
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*.js
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: "@typescript-eslint/parser",
|
|
3
|
+
extends: [
|
|
4
|
+
"plugin:react/recommended",
|
|
5
|
+
"plugin:@typescript-eslint/recommended",
|
|
6
|
+
"prettier",
|
|
7
|
+
],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 2020,
|
|
10
|
+
sourceType: "module",
|
|
11
|
+
},
|
|
12
|
+
settings: {
|
|
13
|
+
react: {
|
|
14
|
+
version: "detect",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
rules: {
|
|
18
|
+
"react/prop-types": "off",
|
|
19
|
+
"@typescript-eslint/no-empty-interface": "off",
|
|
20
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
21
|
+
"@typescript-eslint/ban-types": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
extendDefaults: true,
|
|
25
|
+
types: {
|
|
26
|
+
object: false,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Code Quality
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ${{ matrix.os }}
|
|
18
|
+
strategy:
|
|
19
|
+
matrix:
|
|
20
|
+
os: [ubuntu-22.04, macos-14]
|
|
21
|
+
node-version: [20.x]
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout repository
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
28
|
+
uses: actions/setup-node@v4
|
|
29
|
+
with:
|
|
30
|
+
cache: 'yarn'
|
|
31
|
+
node-version: ${{ matrix.node-version }}
|
|
32
|
+
- run: yarn install --frozen-lockfile --ignore-engines
|
|
33
|
+
- run: yarn ci
|
package/.size-limit.json
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
|
+
|
|
5
|
+
# 4.2.0
|
|
6
|
+
|
|
7
|
+
- Update save-area types and use `initialMetrics` by default
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# 4.1.1
|
|
11
|
+
|
|
12
|
+
- Fix invalid import [#12](https://github.com/retyui/react-native-stylex/issues/12)
|
|
13
|
+
|
|
14
|
+
# 4.1.0
|
|
15
|
+
|
|
16
|
+
- Extend a [Media Query API](docs/media-query.md)
|
|
17
|
+
- `createBreakpointsMatcher(...)` [#8](https://github.com/retyui/react-native-stylex/issues/8)
|
|
18
|
+
- `createBreakpoints(...)`
|
|
19
|
+
|
|
20
|
+
# 4.0.0
|
|
21
|
+
|
|
22
|
+
- Optimize memory usage [#9](https://github.com/retyui/react-native-stylex/issues/9)
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// 4.x.x
|
|
26
|
+
useStyles() === useStyles(); // true
|
|
27
|
+
// 1.x.x - 3.x.x
|
|
28
|
+
useStyles() === useStyles(); // false
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- Add [dimensions api](docs/dimensions.md)
|
|
32
|
+
- Improve [typescript support](docs/ts.md)
|
|
33
|
+
- Add tests for types
|
|
34
|
+
- Update dev dependencies
|
|
35
|
+
|
|
36
|
+
**Breaking changes:**
|
|
37
|
+
|
|
38
|
+
- Type `MakeUseStylesFn<TTheme>` was removed!
|
|
39
|
+
Use [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to define type for `Theme`.
|
|
40
|
+
More info [typescript guide](docs/ts.md)...
|
|
41
|
+
|
|
42
|
+
# 3.1.0
|
|
43
|
+
|
|
44
|
+
- Replace custom module [react-native-appearance](https://github.com/expo/react-native-appearance) with core [react-native Appearance](https://reactnative.dev/docs/appearance)
|
|
45
|
+
|
|
46
|
+
# 3.0.0
|
|
47
|
+
|
|
48
|
+
- Add support for the latest [react-native-safe-area-context@1.0.0](https://github.com/th3rdwave/react-native-safe-area-context/releases/tag/v1.0.0) API
|
|
49
|
+
- Publish a compatible bundle
|
|
50
|
+
- Update dev deps
|
|
51
|
+
|
|
52
|
+
# 2.2.0
|
|
53
|
+
|
|
54
|
+
- Fix expo issue `Unable to resolve module 'module://EmitterSubscription.js'`
|
|
55
|
+
|
|
56
|
+
# 2.1.0
|
|
57
|
+
|
|
58
|
+
- Add integrations with [react-native-appearance](docs/appearance.md)
|
|
59
|
+
|
|
60
|
+
# 2.0.0
|
|
61
|
+
|
|
62
|
+
Deprecate first argument as object `makeUseStyles({ styles: {color: 'red'}})` now only functions allow `makeUseStyles (() => (({ styles: {color : 'red'}}))`
|
|
63
|
+
|
|
64
|
+
Improve memoization logic
|
|
65
|
+
|
|
66
|
+
Add integrations with third party modules\APIs:
|
|
67
|
+
|
|
68
|
+
- [react-native-safe-area](docs/safe-area.md)
|
|
69
|
+
- [react-native-dark-mode](docs/dark-mode.md)
|
|
70
|
+
- [Media Query](docs/media-query.md)
|
|
71
|
+
- [Orientation](docs/orientation.md)
|
|
72
|
+
- [i18n](docs/i18n.md)
|
|
73
|
+
|
|
74
|
+
# 1.1.3
|
|
75
|
+
|
|
76
|
+
- Improve recreating styles
|
|
77
|
+
- Added test
|
|
78
|
+
- Added helper type `MakeUseStylesFn`
|
|
79
|
+
|
|
80
|
+
# 1.1.1
|
|
81
|
+
|
|
82
|
+
- Fix a `makeUseStyles` function type definition
|
|
83
|
+
|
|
84
|
+
# 1.1.0
|
|
85
|
+
|
|
86
|
+
- Added a new helper hook`useColorTransition((theme: Theme) => string): AnimatedValue`
|
|
87
|
+
|
|
88
|
+
# 1.0.0
|
|
89
|
+
|
|
90
|
+
- Release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 David Narbutovich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# react-native-stylex
|
|
2
|
+
|
|
3
|
+
Better styling for react-native
|
|
4
|
+
|
|
5
|
+
[](http://www.npmjs.com/package/react-native-stylex)
|
|
6
|
+
[](https://www.npmtrends.com/react-native-stylex)
|
|
7
|
+
[](https://packagephobia.com/result?p=react-native-stylex)
|
|
8
|
+
[](https://github.com/retyui/react-native-stylex/actions)
|
|
9
|
+
|
|
10
|
+
<div align="center"><img src="https://raw.githubusercontent.com/retyui/react-native-stylex/master/docs/logo.png" width="333"/></div>
|
|
11
|
+
|
|
12
|
+
### Module features:
|
|
13
|
+
|
|
14
|
+
- 📦 Very light and simple;
|
|
15
|
+
- ⚡️ Hooks \ HoC support;
|
|
16
|
+
- 🔋 Theming support;
|
|
17
|
+
- ⛱️ [Typescript support](docs/ts.md);
|
|
18
|
+
- 📝 [Easy integrated with Jest](docs/testting.md).
|
|
19
|
+
|
|
20
|
+
### Integrations
|
|
21
|
+
|
|
22
|
+
- 🛡️ [react-native-safe-area-view](docs/safe-area.md);
|
|
23
|
+
- 🗺 [i18n](docs/i18n.md);
|
|
24
|
+
- 🕳️ [Appearance (a.k.a Dark mode)](docs/appearance.md);
|
|
25
|
+
- 📐 [Dimensions](docs/dimensions.md);
|
|
26
|
+
- 📲 [Orientation](docs/orientation.md);
|
|
27
|
+
- 💉 [Media Queries](docs/media-query.md) support.
|
|
28
|
+
|
|
29
|
+
### Links
|
|
30
|
+
|
|
31
|
+
- [Documentation](docs/api.md);
|
|
32
|
+
- [Live demo](https://snack.expo.io/@retyui/react-native-stylex);
|
|
33
|
+
- [Example app](example/AppStyleX).
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
`react-native-stylex` requires react-native 0.59.0 or later.
|
|
38
|
+
|
|
39
|
+
#### 1️⃣ Add module
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn add react-native-stylex
|
|
43
|
+
|
|
44
|
+
# or npm install react-native-stylex
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### 2️⃣ Add theme `<ThemeProvider/>`
|
|
48
|
+
|
|
49
|
+
Stylex provides component, which makes the theme available to the rest of your app:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { ThemeProvider } from "react-native-stylex";
|
|
53
|
+
import {
|
|
54
|
+
createBreakpointsMatcher,
|
|
55
|
+
createBreakpoints,
|
|
56
|
+
maxWidth,
|
|
57
|
+
} from "react-native-stylex/media-query";
|
|
58
|
+
|
|
59
|
+
const breakpoints = {
|
|
60
|
+
xs: 360,
|
|
61
|
+
sm: 600,
|
|
62
|
+
md: 960,
|
|
63
|
+
lg: 1280,
|
|
64
|
+
xl: 1920,
|
|
65
|
+
};
|
|
66
|
+
const { up, down, only, between } = createBreakpoints(breakpoints);
|
|
67
|
+
const applyBreakpoints = createBreakpointsMatcher(breakpoints, maxWidth);
|
|
68
|
+
|
|
69
|
+
const theme = {
|
|
70
|
+
palette: { textColor: "black" },
|
|
71
|
+
breakpoints: { up, down, only, between, apply: applyBreakpoints },
|
|
72
|
+
utils: {
|
|
73
|
+
fade: (color, value) => {},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const Root = () => (
|
|
78
|
+
<ThemeProvider value={theme}>
|
|
79
|
+
<App />
|
|
80
|
+
</ThemeProvider>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export default Root;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### 3️⃣ Create styles `makeUseStyles(...)`
|
|
87
|
+
|
|
88
|
+
Stylex provides a helper function to inject styles to your component.
|
|
89
|
+
|
|
90
|
+
Normally, you’ll use it in this way:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
94
|
+
import { maxWidth } from "react-native-stylex/media-query";
|
|
95
|
+
|
|
96
|
+
export const useStyles = makeUseStyles(({ palette, utils, breakpoints }) => ({
|
|
97
|
+
root: {
|
|
98
|
+
color: utils.fade(palette.textColor, 0.5),
|
|
99
|
+
height: 100,
|
|
100
|
+
// On screens that are 320 or less, set the height to 69
|
|
101
|
+
...maxWidth(320, { height: 69 }),
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
text: {
|
|
105
|
+
fontSize: 16, // default value
|
|
106
|
+
...breakpoints.down("lg", { fontSize: 18 }), // if window width 0..1280
|
|
107
|
+
...breakpoints.down("sm", { fontSize: 20 }), // if window width 0..600
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
// The same example that you see above but unsing a 'applyBreakpoints'
|
|
111
|
+
title: {
|
|
112
|
+
fontSize: breakpoints.apply({
|
|
113
|
+
sm: 20, // if window width 0....600
|
|
114
|
+
lg: 18, // if window width 601..1280
|
|
115
|
+
default: 16, // if window width 1281...
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
}));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### 4️⃣ Inject styles `useStyles(...)` & `withStyles(...)`
|
|
122
|
+
|
|
123
|
+
And finally just use in component:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
import React, { Component } from "react";
|
|
127
|
+
import useStyles from "./styles";
|
|
128
|
+
|
|
129
|
+
// Functional component (hooks variant)
|
|
130
|
+
const Root = () => {
|
|
131
|
+
const styles = useStyles();
|
|
132
|
+
|
|
133
|
+
return <View style={styles.root} />;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export default Root;
|
|
137
|
+
|
|
138
|
+
//--------------------------------
|
|
139
|
+
|
|
140
|
+
// Class component (HOC variant)
|
|
141
|
+
class Root extends Component {
|
|
142
|
+
render() {
|
|
143
|
+
const { styles } = this.props;
|
|
144
|
+
|
|
145
|
+
return <View style={styles.root} />;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default withStyles(useStyles)(Root);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 5️⃣ Do you use a Typescript ?
|
|
153
|
+
|
|
154
|
+
- Look at [typescript](docs/ts.md) guide
|
|
155
|
+
|
|
156
|
+
### Alternative solutions
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
- [@emotion/native
|
|
160
|
+
](https://emotion.sh/docs/@emotion/native) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
161
|
+
- [nativewind](https://nativewind.dev/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
162
|
+
- [@shopify/restyle](https://shopify.github.io/restyle/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
163
|
+
- [tamagui](https://tamagui.dev/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
164
|
+
- [twrnc](https://github.com/jaredh159/tailwind-react-native-classnames) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
165
|
+
- [tailwind-rn](https://github.com/vadimdemedes/tailwind-rn) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
166
|
+
- [dripsy](https://www.dripsy.xyz/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
167
|
+
- [react-native-unistyles](https://reactnativeunistyles.vercel.app/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
168
|
+
- [react-native-zephyr](https://formidable.com/open-source/react-native-zephyr/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
|
169
|
+
- [@fast-styles/react](https://fedemartinm.github.io/fast-styles/) [](https://npmtrends.com/@emotion/native-vs-@fast-styles/react-vs-@shopify/restyle-vs-dripsy-vs-nativewind-vs-react-native-unistyles-vs-react-native-zephyr-vs-tailwind-rn-vs-tamagui-vs-twrnc)
|
package/babel.config.js
ADDED
package/docs/api.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# API
|
|
2
|
+
|
|
3
|
+
Also read:
|
|
4
|
+
|
|
5
|
+
- [Media query](media-query.md)
|
|
6
|
+
- [Orientation](orientation.md)
|
|
7
|
+
- [I18n](i18n.md)
|
|
8
|
+
- [react-native-safe-area-view](safe-area.md)
|
|
9
|
+
- [react-native-dark-mode](dark-mode.md);
|
|
10
|
+
- [Typescript](ts.md);
|
|
11
|
+
- [Testing with Jest](testting.md).
|
|
12
|
+
|
|
13
|
+
Use a `makeUseStyles` function to create a hook function that can be used in react components
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
17
|
+
|
|
18
|
+
export const useStyles = makeUseStyles((theme) => ({
|
|
19
|
+
root: {
|
|
20
|
+
color: theme.palette.xColor,
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Using styles 🧲
|
|
26
|
+
|
|
27
|
+
You can use styles in function or class components:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import React, { Component } from "react";
|
|
31
|
+
import { useStyles } from "./styles";
|
|
32
|
+
|
|
33
|
+
// Functional component (hooks variant)
|
|
34
|
+
const Root = () => {
|
|
35
|
+
const styles = useStyles();
|
|
36
|
+
|
|
37
|
+
return <View style={styles.root} />;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default Root;
|
|
41
|
+
|
|
42
|
+
// ----------------------------
|
|
43
|
+
// Class component (HOC variant)
|
|
44
|
+
class Root extends Component {
|
|
45
|
+
render() {
|
|
46
|
+
const { styles } = this.props;
|
|
47
|
+
|
|
48
|
+
return <View style={styles.row} />;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default withStyles(useStyles)(Root);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Theming support 🔋
|
|
56
|
+
|
|
57
|
+
You need wrap you're root component with ThemeProvider and pass theme
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { ThemeProvider } from "react-native-stylex";
|
|
61
|
+
|
|
62
|
+
const theme = {
|
|
63
|
+
palette: {
|
|
64
|
+
textColor: "black",
|
|
65
|
+
},
|
|
66
|
+
utils: {
|
|
67
|
+
fade(color, value) {
|
|
68
|
+
/*...*/
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const App = () => (
|
|
74
|
+
<ThemeProvider value={theme}>
|
|
75
|
+
<Root />
|
|
76
|
+
</ThemeProvider>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export default App;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Then use a `makeUseStyles` function and extract passed theme ⚡️
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
86
|
+
import { minWidth } from "react-native-stylex/media-query";
|
|
87
|
+
|
|
88
|
+
// Theme-dependent styles
|
|
89
|
+
const useStyles = makeUseStyles(({ palette, utils }) => ({
|
|
90
|
+
root: {
|
|
91
|
+
color: palette.textColor,
|
|
92
|
+
...minWidth(320, {
|
|
93
|
+
color: utils.fade(palette.textColor, 0.7),
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
const Root = () => {
|
|
99
|
+
const styles = useStyles();
|
|
100
|
+
|
|
101
|
+
return <View style={styles.root} />;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Appearance 🕳️
|
|
2
|
+
|
|
3
|
+
To start using integration with [react-native Appearance](https://reactnative.dev/docs/appearance) module, you need to use react-native [0.62.x](https://reactnative.dev/blog/2020/03/26/version-0.62#new-dark-mode-features).
|
|
4
|
+
|
|
5
|
+
> ⚠️ If you need to support React Native below `0.62.x`, please see [react-native-dark-mode](docs/dark-mode.md)
|
|
6
|
+
|
|
7
|
+
After that you can use special API:
|
|
8
|
+
|
|
9
|
+
- `appearance({ dark, light, default })`
|
|
10
|
+
- `darkAppearance(value)`
|
|
11
|
+
- `lightAppearance(value)`
|
|
12
|
+
- `noPreferenceAppearance(value)`
|
|
13
|
+
|
|
14
|
+
`dark` - The user prefers a dark color theme.
|
|
15
|
+
`light` - The user prefers a light color theme.
|
|
16
|
+
`default` - The user has not indicated a preferred color theme.
|
|
17
|
+
|
|
18
|
+
**Example:**
|
|
19
|
+
|
|
20
|
+
```typescript jsx
|
|
21
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
22
|
+
import {
|
|
23
|
+
appearance,
|
|
24
|
+
darkAppearance,
|
|
25
|
+
lightAppearance,
|
|
26
|
+
noPreferenceAppearance,
|
|
27
|
+
} from "react-native-stylex/appearance";
|
|
28
|
+
|
|
29
|
+
export default makeUseStyles(() => ({
|
|
30
|
+
root: {
|
|
31
|
+
// you can pass styles
|
|
32
|
+
...appearance({
|
|
33
|
+
dark: { color: "#fff", backgroundColor: "#000" },
|
|
34
|
+
light: { color: "#000", backgroundColor: "#fff" },
|
|
35
|
+
}),
|
|
36
|
+
|
|
37
|
+
// or string value for property
|
|
38
|
+
backgroundColor: appearance({ dark: "#000", light: "#fff" }),
|
|
39
|
+
},
|
|
40
|
+
cell: {
|
|
41
|
+
// styles variant
|
|
42
|
+
...lightAppearance({ color: "#000" }),
|
|
43
|
+
// specific value variant
|
|
44
|
+
backgroundColor: lightAppearance("#fff"),
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
row: {
|
|
48
|
+
// styles variant
|
|
49
|
+
...darkAppearance({ color: "#000" }),
|
|
50
|
+
// specific value variant
|
|
51
|
+
backgroundColor: darkAppearance("#fff"),
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Dark mode 🕳️
|
|
2
|
+
|
|
3
|
+
> ⚠️ If you use React Native `0.62.x` and higher, please use [Appearance](docs/appearance.md)
|
|
4
|
+
|
|
5
|
+
To start using integration with [react-native-dark-mode](https://github.com/codemotionapps/react-native-dark-mode) module
|
|
6
|
+
|
|
7
|
+
You need just install it using [instructions](https://github.com/codemotionapps/react-native-dark-mode#installation)!
|
|
8
|
+
|
|
9
|
+
After that you can use special API:
|
|
10
|
+
|
|
11
|
+
- `uiMode({ dark, light })`
|
|
12
|
+
- `darkUiMode(value)`
|
|
13
|
+
- `lightUiMode(value)`
|
|
14
|
+
|
|
15
|
+
**Example:**
|
|
16
|
+
|
|
17
|
+
```typescript jsx
|
|
18
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
19
|
+
import { uiMode, darkUiMode, lightUiMode } from "react-native-stylex/dark-mode";
|
|
20
|
+
|
|
21
|
+
export const useStyles = makeUseStyles(() => ({
|
|
22
|
+
root: {
|
|
23
|
+
// you can pass styles
|
|
24
|
+
...uiMode({
|
|
25
|
+
dark: { color: "#fff", backgroundColor: "#000" },
|
|
26
|
+
light: { color: "#000", backgroundColor: "#fff" },
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
// or string value for property
|
|
30
|
+
backgroundColor: uiMode({ dark: "#000", light: "#fff" }),
|
|
31
|
+
},
|
|
32
|
+
cell: {
|
|
33
|
+
// styles variant
|
|
34
|
+
...lightUiMode({ color: "#000" }),
|
|
35
|
+
// specific value variant
|
|
36
|
+
backgroundColor: lightUiMode("#fff"),
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
row: {
|
|
40
|
+
// styles variant
|
|
41
|
+
...darkUiMode({ color: "#000" }),
|
|
42
|
+
// specific value variant
|
|
43
|
+
backgroundColor: darkUiMode("#fff"),
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Dimensions 📐
|
|
2
|
+
|
|
3
|
+
Nothing special just two helper functions that use [Dimensions](https://reactnative.dev/docs/dimensions) API
|
|
4
|
+
|
|
5
|
+
- `getWindowDimensions`
|
|
6
|
+
- `getScreenDimensions`
|
|
7
|
+
|
|
8
|
+
These functions return an object with the next properties:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
scale: number;
|
|
14
|
+
fontScale: number;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Example:**
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
21
|
+
import { getWindowDimensions } from "react-native-stylex/dimensions";
|
|
22
|
+
|
|
23
|
+
export const useStyles = makeUseStyles(() => ({
|
|
24
|
+
video: {
|
|
25
|
+
width: getWindowDimensions().width,
|
|
26
|
+
height: getWindowDimensions().width,
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
```
|
package/docs/i18n.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# i18n 🗺
|
|
2
|
+
|
|
3
|
+
We use [I18nManager](https://github.com/facebook/react-native/blob/e36247030575e93c1d7087cdb04e1498e9577056/Libraries/ReactNative/I18nManager.js) to handler correct direction
|
|
4
|
+
|
|
5
|
+
**!!! ⚠️ React Native include special mechanism to revert 'left' to 'right' value [`I18nManager.swapLeftAndRightInRTL(true)`](https://reactnative.dev/blog/2017/11/06/react-native-monthly-5#facebook) ⚠️ !!!**
|
|
6
|
+
|
|
7
|
+
- `i18n({ ltr, ltr })`
|
|
8
|
+
- `rtl(value)`
|
|
9
|
+
- `ltr(value)`
|
|
10
|
+
|
|
11
|
+
It means that don't need to use this apis above for setting next values:
|
|
12
|
+
|
|
13
|
+
- Position:
|
|
14
|
+
- (left|right) → (start|end)
|
|
15
|
+
- Margin:
|
|
16
|
+
- margin(Left|Right) → margin(Start|End)
|
|
17
|
+
- Padding:
|
|
18
|
+
- padding(Left|Right) → padding(Start|End)
|
|
19
|
+
- Border:
|
|
20
|
+
- borderTop(Left|Right)Radius → borderTop(Start|End)Radius
|
|
21
|
+
- borderBottom(Left|Right)Radius → borderBottom(Start|End)Radius
|
|
22
|
+
- border(Left|Right)Width → border(Start|End)Width
|
|
23
|
+
- border(Left|Right)Color → border(Start|End)Color
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { i18n } from "react-native-stylex/i18n";
|
|
27
|
+
|
|
28
|
+
// ✅ Good https://reactnative.dev/blog/2017/11/06/react-native-monthly-5#facebook
|
|
29
|
+
good: {
|
|
30
|
+
start: 20,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ❌ Bad
|
|
34
|
+
bad: {
|
|
35
|
+
...i18n({ ltr: { left: 20 }, rtl: { right: 20 } }),
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Example:**
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { makeUseStyles } from "react-native-stylex";
|
|
43
|
+
import { i18n, rtl, ltr } from "react-native-stylex/i18n";
|
|
44
|
+
|
|
45
|
+
export const useStyles = makeUseStyles(() => ({
|
|
46
|
+
root: {
|
|
47
|
+
// you can pass styles
|
|
48
|
+
...i18n({ ltr: { left: 20 }, rtl: { right: 20 } }),
|
|
49
|
+
|
|
50
|
+
// or string value for property
|
|
51
|
+
textAlign: i18n({ ltr: "left", rtl: "right" }),
|
|
52
|
+
},
|
|
53
|
+
cell: {
|
|
54
|
+
// styles variant
|
|
55
|
+
...ltr({ left: 0 }),
|
|
56
|
+
// specific value variant
|
|
57
|
+
alignItems: ltr("flex-start"),
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
row: {
|
|
61
|
+
// styles variant
|
|
62
|
+
...rtl({ right: 0 }),
|
|
63
|
+
// specific value variant
|
|
64
|
+
alignItems: rtl("flex-end"),
|
|
65
|
+
},
|
|
66
|
+
}));
|
|
67
|
+
```
|
package/docs/logo.png
ADDED
|
Binary file
|