@rific/auto-paper 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/README.md +81 -80
- package/dist/index.d.mts +18 -25
- package/dist/index.d.ts +18 -25
- package/dist/index.js +58 -61
- package/dist/index.mjs +54 -49
- package/package.json +55 -41
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jay Deaton
|
|
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
CHANGED
|
@@ -7,8 +7,7 @@ Adaptive theming for [`react-native-paper`](https://callstack.github.io/react-na
|
|
|
7
7
|
- Triadic color palette from a single seed color (primary → secondary → tertiary, 120° apart on the color wheel)
|
|
8
8
|
- System/light/dark appearance with live updates via `Appearance` API
|
|
9
9
|
- Tinted surface, surfaceVariant, outline, and elevation levels derived from the seed
|
|
10
|
-
-
|
|
11
|
-
- Optional Redux slice (`themeReducer`, `themeActions`) for wiring into your store
|
|
10
|
+
- Optional Redux slice for wiring appearance and color into your store
|
|
12
11
|
- All color utilities exported for standalone use
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
@@ -21,97 +20,64 @@ Peer dependencies:
|
|
|
21
20
|
|
|
22
21
|
```bash
|
|
23
22
|
npm install react-native react-native-paper
|
|
24
|
-
# optional — only needed if using splashScreen:
|
|
25
|
-
npm install expo-splash-screen
|
|
26
23
|
```
|
|
27
24
|
|
|
28
25
|
## Usage
|
|
29
26
|
|
|
30
|
-
###
|
|
31
|
-
|
|
32
|
-
Call `configureSplashScreen` at your app entry point before any components mount, then wrap your tree:
|
|
27
|
+
### Provider (simplest)
|
|
33
28
|
|
|
34
29
|
```tsx
|
|
35
|
-
|
|
36
|
-
import { configureSplashScreen } from '@rific/auto-paper'
|
|
37
|
-
configureSplashScreen({ duration: 500, fade: true })
|
|
38
|
-
|
|
39
|
-
// App.tsx
|
|
40
|
-
import { ThemeProvider } from '@rific/auto-paper'
|
|
30
|
+
import { Provider as AutoPaperProvider } from '@rific/auto-paper'
|
|
41
31
|
|
|
42
32
|
export default function App() {
|
|
43
33
|
const [appearance, setAppearance] = useState<'system' | 'light' | 'dark'>('system')
|
|
44
34
|
const [color, setColor] = useState('#6750a4')
|
|
45
35
|
|
|
46
36
|
return (
|
|
47
|
-
<
|
|
37
|
+
<AutoPaperProvider appearance={appearance} color={color}>
|
|
48
38
|
{/* your app */}
|
|
49
|
-
</
|
|
39
|
+
</AutoPaperProvider>
|
|
50
40
|
)
|
|
51
41
|
}
|
|
52
42
|
```
|
|
53
43
|
|
|
54
|
-
`
|
|
55
|
-
|
|
56
|
-
### With React Navigation
|
|
57
|
-
|
|
58
|
-
Use the `useComputedTheme` hook directly to integrate with Navigation's `ThemeProvider`:
|
|
44
|
+
`Provider` renders `null` on the first render while the theme computes, then wraps your app in `PaperProvider` with the computed theme, a matching `StatusBar`, and a background `View`. Use `onReady` to hook into that moment — e.g. to dismiss a splash screen:
|
|
59
45
|
|
|
60
46
|
```tsx
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export default function App() {
|
|
66
|
-
const theme = useComputedTheme('system', '#6750a4')
|
|
67
|
-
if (!theme) return null
|
|
68
|
-
|
|
69
|
-
const navTheme = {
|
|
70
|
-
...(theme.dark ? DarkTheme : DefaultTheme),
|
|
71
|
-
colors: {
|
|
72
|
-
...(theme.dark ? DarkTheme : DefaultTheme).colors,
|
|
73
|
-
background: theme.colors.background,
|
|
74
|
-
card: theme.colors.background
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<NavThemeProvider value={navTheme}>
|
|
80
|
-
<PaperProvider theme={theme}>
|
|
81
|
-
{/* your app */}
|
|
82
|
-
</PaperProvider>
|
|
83
|
-
</NavThemeProvider>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
47
|
+
<AutoPaperProvider appearance={appearance} color={color} onReady={SplashScreen.hideAsync}>
|
|
48
|
+
{/* your app */}
|
|
49
|
+
</AutoPaperProvider>
|
|
86
50
|
```
|
|
87
51
|
|
|
88
52
|
### With Redux
|
|
89
53
|
|
|
90
|
-
The package exports an optional Redux slice.
|
|
54
|
+
The package exports an optional Redux slice. Use `createThemeReducer` to register it in your store with a custom initial color:
|
|
91
55
|
|
|
92
56
|
```ts
|
|
93
57
|
// store.ts
|
|
94
|
-
import {
|
|
58
|
+
import { createThemeReducer, themeActions } from '@rific/auto-paper'
|
|
95
59
|
|
|
96
60
|
export const store = configureStore({
|
|
97
61
|
reducer: {
|
|
98
|
-
theme:
|
|
62
|
+
theme: createThemeReducer({ color: '#4caf50' }),
|
|
99
63
|
// ...
|
|
100
64
|
}
|
|
101
65
|
})
|
|
102
66
|
```
|
|
103
67
|
|
|
68
|
+
Then read from the store and pass into `Provider`:
|
|
69
|
+
|
|
104
70
|
```tsx
|
|
105
71
|
// App.tsx
|
|
106
72
|
import { useSelector } from 'react-redux'
|
|
107
|
-
import {
|
|
73
|
+
import { Provider as AutoPaperProvider } from '@rific/auto-paper'
|
|
108
74
|
|
|
109
75
|
export default function App() {
|
|
110
|
-
const { appearance, color } = useSelector((state) => state.theme)
|
|
76
|
+
const { appearance, color } = useSelector((state: RootState) => state.theme)
|
|
111
77
|
return (
|
|
112
|
-
<
|
|
78
|
+
<AutoPaperProvider appearance={appearance} color={color} onReady={SplashScreen.hideAsync}>
|
|
113
79
|
{/* your app */}
|
|
114
|
-
</
|
|
80
|
+
</AutoPaperProvider>
|
|
115
81
|
)
|
|
116
82
|
}
|
|
117
83
|
```
|
|
@@ -125,37 +91,84 @@ dispatch(themeActions.setColor('#e91e63'))
|
|
|
125
91
|
dispatch(themeActions.setAppearance('dark'))
|
|
126
92
|
```
|
|
127
93
|
|
|
128
|
-
|
|
94
|
+
### With `useComputedTheme`
|
|
129
95
|
|
|
130
|
-
|
|
131
|
-
|
|
96
|
+
Use the hook directly when you need to extend the theme before passing it to `PaperProvider` — for example, to merge in a navigation theme or add custom color keys:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { useComputedTheme } from '@rific/auto-paper'
|
|
100
|
+
import { DarkTheme, DefaultTheme, ThemeProvider as NavThemeProvider } from '@react-navigation/native'
|
|
101
|
+
import { Provider as PaperProvider } from 'react-native-paper'
|
|
102
|
+
|
|
103
|
+
export default function App() {
|
|
104
|
+
const theme = useComputedTheme('system', '#6750a4')
|
|
105
|
+
if (!theme) return null
|
|
106
|
+
|
|
107
|
+
const navTheme = {
|
|
108
|
+
...(theme.dark ? DarkTheme : DefaultTheme),
|
|
109
|
+
colors: {
|
|
110
|
+
...(theme.dark ? DarkTheme : DefaultTheme).colors,
|
|
111
|
+
background: theme.colors.background,
|
|
112
|
+
card: theme.colors.background
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<NavThemeProvider value={navTheme}>
|
|
118
|
+
<PaperProvider theme={theme}>
|
|
119
|
+
{/* your app */}
|
|
120
|
+
</PaperProvider>
|
|
121
|
+
</NavThemeProvider>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
132
124
|
```
|
|
133
125
|
|
|
134
126
|
## API
|
|
135
127
|
|
|
136
|
-
### `
|
|
128
|
+
### `Provider`
|
|
137
129
|
|
|
138
|
-
| Prop | Type |
|
|
139
|
-
|
|
140
|
-
| `appearance` | `'system' \| 'light' \| 'dark'` |
|
|
141
|
-
| `color` | `string` |
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
130
|
+
| Prop | Type | Description |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| `appearance` | `'system' \| 'light' \| 'dark'` | Appearance mode |
|
|
133
|
+
| `color` | `string` | Seed color (hex, rgb, or CSS name) |
|
|
134
|
+
| `children` | `ReactNode` | |
|
|
135
|
+
| `onReady` | `() => void` | Called once when the theme first resolves |
|
|
136
|
+
| `statusBarProps` | `StatusBarProps` | Spread over the auto-derived `StatusBar` defaults |
|
|
137
|
+
| `style` | `StyleProp<ViewStyle>` | Applied to the wrapper `View` |
|
|
144
138
|
|
|
145
|
-
### `useComputedTheme(appearance, color
|
|
139
|
+
### `useComputedTheme(appearance, color)`
|
|
146
140
|
|
|
147
|
-
Returns `MD3Theme | null`. `null`
|
|
141
|
+
Returns `MD3Theme | null`. `null` on the first render while the theme computes.
|
|
148
142
|
|
|
149
143
|
```ts
|
|
150
|
-
const theme = useComputedTheme('system', '#6750a4'
|
|
144
|
+
const theme = useComputedTheme('system', '#6750a4')
|
|
151
145
|
```
|
|
152
146
|
|
|
153
|
-
### `
|
|
147
|
+
### `createThemeReducer(initialState?)`
|
|
148
|
+
|
|
149
|
+
Returns a Redux reducer with an optional initial state override. Useful for setting a custom default color without dispatching an action at startup.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
createThemeReducer({ color: '#4caf50' })
|
|
153
|
+
```
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
### Redux exports
|
|
156
156
|
|
|
157
157
|
```ts
|
|
158
|
-
|
|
158
|
+
import { themeReducer, themeActions, selectThemeAppearance, selectThemeColor } from '@rific/auto-paper'
|
|
159
|
+
import type { ThemeState, ThemeAppearance } from '@rific/auto-paper'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| Action | Payload |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `initialize` | `Partial<ThemeState>` |
|
|
165
|
+
| `setAppearance` | `ThemeAppearance` |
|
|
166
|
+
| `setColor` | `string` |
|
|
167
|
+
|
|
168
|
+
Selectors accept `ThemeState` directly — compose them with your root state selector:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const appearance = useSelector((state: RootState) => selectThemeAppearance(state.theme))
|
|
159
172
|
```
|
|
160
173
|
|
|
161
174
|
### Color utilities
|
|
@@ -172,18 +185,6 @@ getRgb('coral') // → { r: 255, g: 127, b: 80 }
|
|
|
172
185
|
getHex('rgb(255, 0, 0)') // → '#ff0000'
|
|
173
186
|
```
|
|
174
187
|
|
|
175
|
-
### Redux slice
|
|
176
|
-
|
|
177
|
-
```ts
|
|
178
|
-
import { themeReducer, themeActions, ThemeState, ThemeAppearance } from '@rific/auto-paper'
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
| Action | Payload |
|
|
182
|
-
|---|---|
|
|
183
|
-
| `initialize` | `Partial<ThemeState>` |
|
|
184
|
-
| `setAppearance` | `ThemeAppearance` |
|
|
185
|
-
| `setColor` | `string` |
|
|
186
|
-
|
|
187
188
|
## License
|
|
188
189
|
|
|
189
190
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,56 +1,49 @@
|
|
|
1
|
-
import * as redux from 'redux';
|
|
2
1
|
import * as _reduxjs_toolkit from '@reduxjs/toolkit';
|
|
3
2
|
import { PayloadAction } from '@reduxjs/toolkit';
|
|
3
|
+
import * as redux from 'redux';
|
|
4
4
|
import { MD3Theme } from 'react-native-paper';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
|
+
import { StatusBarProps, StyleProp, ViewStyle } from 'react-native';
|
|
7
8
|
|
|
8
9
|
type ThemeAppearance = 'system' | 'light' | 'dark';
|
|
9
|
-
|
|
10
|
-
splashScreen?: boolean;
|
|
11
|
-
};
|
|
12
|
-
declare function useComputedTheme(appearance: ThemeAppearance, color: string, options?: ComputedThemeOptions): MD3Theme | null;
|
|
10
|
+
declare function useComputedTheme(appearance: ThemeAppearance, color: string): MD3Theme | null;
|
|
13
11
|
|
|
14
12
|
type ThemeState = {
|
|
15
13
|
appearance: ThemeAppearance;
|
|
16
14
|
color: string;
|
|
17
15
|
};
|
|
16
|
+
declare function createThemeReducer(initialState?: Partial<ThemeState>): redux.Reducer<{
|
|
17
|
+
appearance: ThemeAppearance;
|
|
18
|
+
color: string;
|
|
19
|
+
}>;
|
|
18
20
|
declare const themeActions: _reduxjs_toolkit.CaseReducerActions<{
|
|
19
|
-
initialize: (state: {
|
|
20
|
-
appearance: ThemeAppearance;
|
|
21
|
-
color: string;
|
|
22
|
-
}, action: PayloadAction<Partial<ThemeState>>) => {
|
|
21
|
+
initialize: (state: ThemeState, action: PayloadAction<Partial<ThemeState>>) => {
|
|
23
22
|
appearance: ThemeAppearance;
|
|
24
23
|
color: string;
|
|
25
24
|
};
|
|
26
|
-
setAppearance: (state: {
|
|
27
|
-
appearance: ThemeAppearance;
|
|
28
|
-
color: string;
|
|
29
|
-
}, action: PayloadAction<ThemeAppearance>) => {
|
|
25
|
+
setAppearance: (state: ThemeState, action: PayloadAction<ThemeAppearance>) => {
|
|
30
26
|
appearance: ThemeAppearance;
|
|
31
27
|
color: string;
|
|
32
28
|
};
|
|
33
|
-
setColor: (state: {
|
|
34
|
-
appearance: ThemeAppearance;
|
|
35
|
-
color: string;
|
|
36
|
-
}, action: PayloadAction<string>) => {
|
|
29
|
+
setColor: (state: ThemeState, action: PayloadAction<string>) => {
|
|
37
30
|
color: string;
|
|
38
31
|
appearance: ThemeAppearance;
|
|
39
32
|
};
|
|
40
33
|
}, "theme">;
|
|
41
34
|
declare const themeReducer: redux.Reducer<ThemeState>;
|
|
35
|
+
declare const selectThemeAppearance: (state: ThemeState) => ThemeAppearance;
|
|
36
|
+
declare const selectThemeColor: (state: ThemeState) => string;
|
|
42
37
|
|
|
43
|
-
type
|
|
38
|
+
type ProviderProps = {
|
|
44
39
|
appearance: ThemeAppearance;
|
|
45
40
|
color: string;
|
|
46
|
-
splashScreen?: boolean;
|
|
47
41
|
children: ReactNode;
|
|
42
|
+
onReady?: () => void;
|
|
43
|
+
statusBarProps?: StatusBarProps;
|
|
44
|
+
style?: StyleProp<ViewStyle>;
|
|
48
45
|
};
|
|
49
|
-
declare function
|
|
50
|
-
duration?: number;
|
|
51
|
-
fade?: boolean;
|
|
52
|
-
}): void;
|
|
53
|
-
declare function ThemeProvider({ appearance, color, splashScreen, children }: ThemeProviderProps): react.JSX.Element | null;
|
|
46
|
+
declare function Provider({ appearance, color, children, onReady, statusBarProps, style }: ProviderProps): react.JSX.Element | null;
|
|
54
47
|
|
|
55
48
|
declare const getBlendedColor: (foreground: string, background: string, alpha: number) => string;
|
|
56
49
|
|
|
@@ -73,4 +66,4 @@ declare function getTriadicPalette(primaryColor: string): TriadicPalette;
|
|
|
73
66
|
|
|
74
67
|
declare const isDarkColor: (value: string) => boolean;
|
|
75
68
|
|
|
76
|
-
export { type
|
|
69
|
+
export { Provider, type ProviderProps, type RGB, type ThemeAppearance, type ThemeState, type TriadicPalette, createThemeReducer, getBlendedColor, getHex, getRgb, getTriadicPalette, isDarkColor, selectThemeAppearance, selectThemeColor, themeActions, themeReducer, useComputedTheme };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,56 +1,49 @@
|
|
|
1
|
-
import * as redux from 'redux';
|
|
2
1
|
import * as _reduxjs_toolkit from '@reduxjs/toolkit';
|
|
3
2
|
import { PayloadAction } from '@reduxjs/toolkit';
|
|
3
|
+
import * as redux from 'redux';
|
|
4
4
|
import { MD3Theme } from 'react-native-paper';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
|
+
import { StatusBarProps, StyleProp, ViewStyle } from 'react-native';
|
|
7
8
|
|
|
8
9
|
type ThemeAppearance = 'system' | 'light' | 'dark';
|
|
9
|
-
|
|
10
|
-
splashScreen?: boolean;
|
|
11
|
-
};
|
|
12
|
-
declare function useComputedTheme(appearance: ThemeAppearance, color: string, options?: ComputedThemeOptions): MD3Theme | null;
|
|
10
|
+
declare function useComputedTheme(appearance: ThemeAppearance, color: string): MD3Theme | null;
|
|
13
11
|
|
|
14
12
|
type ThemeState = {
|
|
15
13
|
appearance: ThemeAppearance;
|
|
16
14
|
color: string;
|
|
17
15
|
};
|
|
16
|
+
declare function createThemeReducer(initialState?: Partial<ThemeState>): redux.Reducer<{
|
|
17
|
+
appearance: ThemeAppearance;
|
|
18
|
+
color: string;
|
|
19
|
+
}>;
|
|
18
20
|
declare const themeActions: _reduxjs_toolkit.CaseReducerActions<{
|
|
19
|
-
initialize: (state: {
|
|
20
|
-
appearance: ThemeAppearance;
|
|
21
|
-
color: string;
|
|
22
|
-
}, action: PayloadAction<Partial<ThemeState>>) => {
|
|
21
|
+
initialize: (state: ThemeState, action: PayloadAction<Partial<ThemeState>>) => {
|
|
23
22
|
appearance: ThemeAppearance;
|
|
24
23
|
color: string;
|
|
25
24
|
};
|
|
26
|
-
setAppearance: (state: {
|
|
27
|
-
appearance: ThemeAppearance;
|
|
28
|
-
color: string;
|
|
29
|
-
}, action: PayloadAction<ThemeAppearance>) => {
|
|
25
|
+
setAppearance: (state: ThemeState, action: PayloadAction<ThemeAppearance>) => {
|
|
30
26
|
appearance: ThemeAppearance;
|
|
31
27
|
color: string;
|
|
32
28
|
};
|
|
33
|
-
setColor: (state: {
|
|
34
|
-
appearance: ThemeAppearance;
|
|
35
|
-
color: string;
|
|
36
|
-
}, action: PayloadAction<string>) => {
|
|
29
|
+
setColor: (state: ThemeState, action: PayloadAction<string>) => {
|
|
37
30
|
color: string;
|
|
38
31
|
appearance: ThemeAppearance;
|
|
39
32
|
};
|
|
40
33
|
}, "theme">;
|
|
41
34
|
declare const themeReducer: redux.Reducer<ThemeState>;
|
|
35
|
+
declare const selectThemeAppearance: (state: ThemeState) => ThemeAppearance;
|
|
36
|
+
declare const selectThemeColor: (state: ThemeState) => string;
|
|
42
37
|
|
|
43
|
-
type
|
|
38
|
+
type ProviderProps = {
|
|
44
39
|
appearance: ThemeAppearance;
|
|
45
40
|
color: string;
|
|
46
|
-
splashScreen?: boolean;
|
|
47
41
|
children: ReactNode;
|
|
42
|
+
onReady?: () => void;
|
|
43
|
+
statusBarProps?: StatusBarProps;
|
|
44
|
+
style?: StyleProp<ViewStyle>;
|
|
48
45
|
};
|
|
49
|
-
declare function
|
|
50
|
-
duration?: number;
|
|
51
|
-
fade?: boolean;
|
|
52
|
-
}): void;
|
|
53
|
-
declare function ThemeProvider({ appearance, color, splashScreen, children }: ThemeProviderProps): react.JSX.Element | null;
|
|
46
|
+
declare function Provider({ appearance, color, children, onReady, statusBarProps, style }: ProviderProps): react.JSX.Element | null;
|
|
54
47
|
|
|
55
48
|
declare const getBlendedColor: (foreground: string, background: string, alpha: number) => string;
|
|
56
49
|
|
|
@@ -73,4 +66,4 @@ declare function getTriadicPalette(primaryColor: string): TriadicPalette;
|
|
|
73
66
|
|
|
74
67
|
declare const isDarkColor: (value: string) => boolean;
|
|
75
68
|
|
|
76
|
-
export { type
|
|
69
|
+
export { Provider, type ProviderProps, type RGB, type ThemeAppearance, type ThemeState, type TriadicPalette, createThemeReducer, getBlendedColor, getHex, getRgb, getTriadicPalette, isDarkColor, selectThemeAppearance, selectThemeColor, themeActions, themeReducer, useComputedTheme };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
7
|
var __export = (target, all) => {
|
|
@@ -18,27 +16,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
}
|
|
19
17
|
return to;
|
|
20
18
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
21
|
|
|
32
22
|
// src/index.ts
|
|
33
23
|
var index_exports = {};
|
|
34
24
|
__export(index_exports, {
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
Provider: () => Provider,
|
|
26
|
+
createThemeReducer: () => createThemeReducer,
|
|
37
27
|
getBlendedColor: () => getBlendedColor,
|
|
38
28
|
getHex: () => getHex,
|
|
39
29
|
getRgb: () => getRgb,
|
|
40
30
|
getTriadicPalette: () => getTriadicPalette,
|
|
41
31
|
isDarkColor: () => isDarkColor,
|
|
32
|
+
selectThemeAppearance: () => selectThemeAppearance,
|
|
33
|
+
selectThemeColor: () => selectThemeColor,
|
|
42
34
|
themeActions: () => themeActions,
|
|
43
35
|
themeReducer: () => themeReducer,
|
|
44
36
|
useComputedTheme: () => useComputedTheme
|
|
@@ -969,18 +961,18 @@ function executeReducerBuilderCallback(builderCallback) {
|
|
|
969
961
|
actionsMap[type] = reducer;
|
|
970
962
|
return builder;
|
|
971
963
|
},
|
|
972
|
-
addAsyncThunk(asyncThunk,
|
|
964
|
+
addAsyncThunk(asyncThunk, reducers2) {
|
|
973
965
|
if (process.env.NODE_ENV !== "production") {
|
|
974
966
|
if (defaultCaseReducer) {
|
|
975
967
|
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
|
|
976
968
|
}
|
|
977
969
|
}
|
|
978
|
-
if (
|
|
979
|
-
if (
|
|
980
|
-
if (
|
|
981
|
-
if (
|
|
970
|
+
if (reducers2.pending) actionsMap[asyncThunk.pending.type] = reducers2.pending;
|
|
971
|
+
if (reducers2.rejected) actionsMap[asyncThunk.rejected.type] = reducers2.rejected;
|
|
972
|
+
if (reducers2.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers2.fulfilled;
|
|
973
|
+
if (reducers2.settled) actionMatchers.push({
|
|
982
974
|
matcher: asyncThunk.settled,
|
|
983
|
-
reducer:
|
|
975
|
+
reducer: reducers2.settled
|
|
984
976
|
});
|
|
985
977
|
return builder;
|
|
986
978
|
},
|
|
@@ -1012,7 +1004,7 @@ function executeReducerBuilderCallback(builderCallback) {
|
|
|
1012
1004
|
function isStateFunction(x) {
|
|
1013
1005
|
return typeof x === "function";
|
|
1014
1006
|
}
|
|
1015
|
-
function createReducer(
|
|
1007
|
+
function createReducer(initialState, mapOrBuilderCallback) {
|
|
1016
1008
|
if (process.env.NODE_ENV !== "production") {
|
|
1017
1009
|
if (typeof mapOrBuilderCallback === "object") {
|
|
1018
1010
|
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
@@ -1020,10 +1012,10 @@ function createReducer(initialState2, mapOrBuilderCallback) {
|
|
|
1020
1012
|
}
|
|
1021
1013
|
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
1022
1014
|
let getInitialState;
|
|
1023
|
-
if (isStateFunction(
|
|
1024
|
-
getInitialState = () => freezeDraftable(
|
|
1015
|
+
if (isStateFunction(initialState)) {
|
|
1016
|
+
getInitialState = () => freezeDraftable(initialState());
|
|
1025
1017
|
} else {
|
|
1026
|
-
const frozenInitialState = freezeDraftable(
|
|
1018
|
+
const frozenInitialState = freezeDraftable(initialState);
|
|
1027
1019
|
getInitialState = () => frozenInitialState;
|
|
1028
1020
|
}
|
|
1029
1021
|
function reducer(state = getInitialState(), action) {
|
|
@@ -1288,8 +1280,8 @@ var asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
|
1288
1280
|
var asyncThunkCreator = {
|
|
1289
1281
|
[asyncThunkSymbol]: createAsyncThunk
|
|
1290
1282
|
};
|
|
1291
|
-
function getType(
|
|
1292
|
-
return `${
|
|
1283
|
+
function getType(slice, actionKey) {
|
|
1284
|
+
return `${slice}/${actionKey}`;
|
|
1293
1285
|
}
|
|
1294
1286
|
function buildCreateSlice({
|
|
1295
1287
|
creators
|
|
@@ -1308,8 +1300,8 @@ function buildCreateSlice({
|
|
|
1308
1300
|
console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
1309
1301
|
}
|
|
1310
1302
|
}
|
|
1311
|
-
const
|
|
1312
|
-
const reducerNames = Object.keys(
|
|
1303
|
+
const reducers2 = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
1304
|
+
const reducerNames = Object.keys(reducers2);
|
|
1313
1305
|
const context = {
|
|
1314
1306
|
sliceCaseReducersByName: {},
|
|
1315
1307
|
sliceCaseReducersByType: {},
|
|
@@ -1345,7 +1337,7 @@ function buildCreateSlice({
|
|
|
1345
1337
|
}
|
|
1346
1338
|
};
|
|
1347
1339
|
reducerNames.forEach((reducerName) => {
|
|
1348
|
-
const reducerDefinition =
|
|
1340
|
+
const reducerDefinition = reducers2[reducerName];
|
|
1349
1341
|
const reducerDetails = {
|
|
1350
1342
|
reducerName,
|
|
1351
1343
|
type: getType(name, reducerName),
|
|
@@ -1426,7 +1418,7 @@ function buildCreateSlice({
|
|
|
1426
1418
|
selectSlice
|
|
1427
1419
|
};
|
|
1428
1420
|
}
|
|
1429
|
-
const
|
|
1421
|
+
const slice = {
|
|
1430
1422
|
name,
|
|
1431
1423
|
reducer,
|
|
1432
1424
|
actions: context.actionCreators,
|
|
@@ -1443,12 +1435,12 @@ function buildCreateSlice({
|
|
|
1443
1435
|
reducer
|
|
1444
1436
|
}, config);
|
|
1445
1437
|
return {
|
|
1446
|
-
...
|
|
1438
|
+
...slice,
|
|
1447
1439
|
...makeSelectorProps(newReducerPath, true)
|
|
1448
1440
|
};
|
|
1449
1441
|
}
|
|
1450
1442
|
};
|
|
1451
|
-
return
|
|
1443
|
+
return slice;
|
|
1452
1444
|
};
|
|
1453
1445
|
}
|
|
1454
1446
|
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
@@ -1584,29 +1576,38 @@ function formatProdErrorMessage(code) {
|
|
|
1584
1576
|
}
|
|
1585
1577
|
|
|
1586
1578
|
// src/redux/themeSlice.ts
|
|
1587
|
-
var
|
|
1579
|
+
var defaultInitialState = {
|
|
1588
1580
|
appearance: "system",
|
|
1589
1581
|
color: "#6750a4"
|
|
1590
1582
|
};
|
|
1591
|
-
var
|
|
1583
|
+
var reducers = {
|
|
1584
|
+
initialize: (state, action) => ({ ...state, ...action.payload }),
|
|
1585
|
+
setAppearance: (state, action) => ({ ...state, appearance: action.payload }),
|
|
1586
|
+
setColor: (state, action) => ({ ...state, color: action.payload })
|
|
1587
|
+
};
|
|
1588
|
+
function createThemeReducer(initialState) {
|
|
1589
|
+
return createSlice({
|
|
1590
|
+
name: "theme",
|
|
1591
|
+
initialState: { ...defaultInitialState, ...initialState },
|
|
1592
|
+
reducers
|
|
1593
|
+
}).reducer;
|
|
1594
|
+
}
|
|
1595
|
+
var defaultSlice = createSlice({
|
|
1592
1596
|
name: "theme",
|
|
1593
|
-
initialState,
|
|
1594
|
-
reducers
|
|
1595
|
-
initialize: (state, action) => ({ ...state, ...action.payload }),
|
|
1596
|
-
setAppearance: (state, action) => ({ ...state, appearance: action.payload }),
|
|
1597
|
-
setColor: (state, action) => ({ ...state, color: action.payload })
|
|
1598
|
-
}
|
|
1597
|
+
initialState: defaultInitialState,
|
|
1598
|
+
reducers
|
|
1599
1599
|
});
|
|
1600
|
-
var themeActions =
|
|
1601
|
-
var themeReducer =
|
|
1600
|
+
var themeActions = defaultSlice.actions;
|
|
1601
|
+
var themeReducer = defaultSlice.reducer;
|
|
1602
|
+
var selectThemeAppearance = (state) => state.appearance;
|
|
1603
|
+
var selectThemeColor = (state) => state.color;
|
|
1602
1604
|
|
|
1603
1605
|
// src/ThemeProvider.tsx
|
|
1604
|
-
var
|
|
1606
|
+
var import_react2 = require("react");
|
|
1605
1607
|
var import_react_native2 = require("react-native");
|
|
1606
1608
|
var import_react_native_paper2 = require("react-native-paper");
|
|
1607
1609
|
|
|
1608
1610
|
// src/useComputedTheme.ts
|
|
1609
|
-
var SplashScreen = __toESM(require("expo-splash-screen"));
|
|
1610
1611
|
var import_react = require("react");
|
|
1611
1612
|
var import_react_native = require("react-native");
|
|
1612
1613
|
var import_react_native_paper = require("react-native-paper");
|
|
@@ -1919,8 +1920,7 @@ var isDarkColor = (value) => {
|
|
|
1919
1920
|
};
|
|
1920
1921
|
|
|
1921
1922
|
// src/useComputedTheme.ts
|
|
1922
|
-
function useComputedTheme(appearance, color
|
|
1923
|
-
const splashScreen = options?.splashScreen !== false;
|
|
1923
|
+
function useComputedTheme(appearance, color) {
|
|
1924
1924
|
const [theme, setTheme] = (0, import_react.useState)(null);
|
|
1925
1925
|
const computeTheme = (0, import_react.useCallback)(() => {
|
|
1926
1926
|
let resolved = appearance;
|
|
@@ -1972,39 +1972,36 @@ function useComputedTheme(appearance, color, options) {
|
|
|
1972
1972
|
const subscription = import_react_native.Appearance.addChangeListener(computeTheme);
|
|
1973
1973
|
return subscription.remove;
|
|
1974
1974
|
}, [computeTheme]);
|
|
1975
|
-
(0, import_react.useEffect)(() => {
|
|
1976
|
-
if (theme && splashScreen) SplashScreen.hideAsync();
|
|
1977
|
-
}, [theme, splashScreen]);
|
|
1978
1975
|
return theme;
|
|
1979
1976
|
}
|
|
1980
1977
|
|
|
1981
1978
|
// src/ThemeProvider.tsx
|
|
1982
|
-
function
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
}
|
|
1991
|
-
function ThemeProvider({ appearance, color, splashScreen = true, children }) {
|
|
1992
|
-
const theme = useComputedTheme(appearance, color, { splashScreen });
|
|
1979
|
+
function Provider({ appearance, color, children, onReady, statusBarProps, style }) {
|
|
1980
|
+
const theme = useComputedTheme(appearance, color);
|
|
1981
|
+
const called = (0, import_react2.useRef)(false);
|
|
1982
|
+
(0, import_react2.useEffect)(() => {
|
|
1983
|
+
if (theme && !called.current) {
|
|
1984
|
+
called.current = true;
|
|
1985
|
+
onReady?.();
|
|
1986
|
+
}
|
|
1987
|
+
}, [theme, onReady]);
|
|
1993
1988
|
if (!theme) return null;
|
|
1994
|
-
return /* @__PURE__ */ React.createElement(import_react_native_paper2.Provider, { theme }, /* @__PURE__ */ React.createElement(import_react_native2.StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content" }), /* @__PURE__ */ React.createElement(import_react_native2.View, { style: styles.flex }, children));
|
|
1989
|
+
return /* @__PURE__ */ React.createElement(import_react_native_paper2.Provider, { theme }, /* @__PURE__ */ React.createElement(import_react_native2.StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content", ...statusBarProps }), /* @__PURE__ */ React.createElement(import_react_native2.View, { style: [styles.flex, { backgroundColor: theme.colors.background }, style] }, children));
|
|
1995
1990
|
}
|
|
1996
1991
|
var styles = import_react_native2.StyleSheet.create({
|
|
1997
1992
|
flex: { flex: 1 }
|
|
1998
1993
|
});
|
|
1999
1994
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2000
1995
|
0 && (module.exports = {
|
|
2001
|
-
|
|
2002
|
-
|
|
1996
|
+
Provider,
|
|
1997
|
+
createThemeReducer,
|
|
2003
1998
|
getBlendedColor,
|
|
2004
1999
|
getHex,
|
|
2005
2000
|
getRgb,
|
|
2006
2001
|
getTriadicPalette,
|
|
2007
2002
|
isDarkColor,
|
|
2003
|
+
selectThemeAppearance,
|
|
2004
|
+
selectThemeColor,
|
|
2008
2005
|
themeActions,
|
|
2009
2006
|
themeReducer,
|
|
2010
2007
|
useComputedTheme
|
package/dist/index.mjs
CHANGED
|
@@ -926,18 +926,18 @@ function executeReducerBuilderCallback(builderCallback) {
|
|
|
926
926
|
actionsMap[type] = reducer;
|
|
927
927
|
return builder;
|
|
928
928
|
},
|
|
929
|
-
addAsyncThunk(asyncThunk,
|
|
929
|
+
addAsyncThunk(asyncThunk, reducers2) {
|
|
930
930
|
if (process.env.NODE_ENV !== "production") {
|
|
931
931
|
if (defaultCaseReducer) {
|
|
932
932
|
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
|
|
933
933
|
}
|
|
934
934
|
}
|
|
935
|
-
if (
|
|
936
|
-
if (
|
|
937
|
-
if (
|
|
938
|
-
if (
|
|
935
|
+
if (reducers2.pending) actionsMap[asyncThunk.pending.type] = reducers2.pending;
|
|
936
|
+
if (reducers2.rejected) actionsMap[asyncThunk.rejected.type] = reducers2.rejected;
|
|
937
|
+
if (reducers2.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers2.fulfilled;
|
|
938
|
+
if (reducers2.settled) actionMatchers.push({
|
|
939
939
|
matcher: asyncThunk.settled,
|
|
940
|
-
reducer:
|
|
940
|
+
reducer: reducers2.settled
|
|
941
941
|
});
|
|
942
942
|
return builder;
|
|
943
943
|
},
|
|
@@ -969,7 +969,7 @@ function executeReducerBuilderCallback(builderCallback) {
|
|
|
969
969
|
function isStateFunction(x) {
|
|
970
970
|
return typeof x === "function";
|
|
971
971
|
}
|
|
972
|
-
function createReducer(
|
|
972
|
+
function createReducer(initialState, mapOrBuilderCallback) {
|
|
973
973
|
if (process.env.NODE_ENV !== "production") {
|
|
974
974
|
if (typeof mapOrBuilderCallback === "object") {
|
|
975
975
|
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
@@ -977,10 +977,10 @@ function createReducer(initialState2, mapOrBuilderCallback) {
|
|
|
977
977
|
}
|
|
978
978
|
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
979
979
|
let getInitialState;
|
|
980
|
-
if (isStateFunction(
|
|
981
|
-
getInitialState = () => freezeDraftable(
|
|
980
|
+
if (isStateFunction(initialState)) {
|
|
981
|
+
getInitialState = () => freezeDraftable(initialState());
|
|
982
982
|
} else {
|
|
983
|
-
const frozenInitialState = freezeDraftable(
|
|
983
|
+
const frozenInitialState = freezeDraftable(initialState);
|
|
984
984
|
getInitialState = () => frozenInitialState;
|
|
985
985
|
}
|
|
986
986
|
function reducer(state = getInitialState(), action) {
|
|
@@ -1245,8 +1245,8 @@ var asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
|
1245
1245
|
var asyncThunkCreator = {
|
|
1246
1246
|
[asyncThunkSymbol]: createAsyncThunk
|
|
1247
1247
|
};
|
|
1248
|
-
function getType(
|
|
1249
|
-
return `${
|
|
1248
|
+
function getType(slice, actionKey) {
|
|
1249
|
+
return `${slice}/${actionKey}`;
|
|
1250
1250
|
}
|
|
1251
1251
|
function buildCreateSlice({
|
|
1252
1252
|
creators
|
|
@@ -1265,8 +1265,8 @@ function buildCreateSlice({
|
|
|
1265
1265
|
console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
1266
1266
|
}
|
|
1267
1267
|
}
|
|
1268
|
-
const
|
|
1269
|
-
const reducerNames = Object.keys(
|
|
1268
|
+
const reducers2 = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
1269
|
+
const reducerNames = Object.keys(reducers2);
|
|
1270
1270
|
const context = {
|
|
1271
1271
|
sliceCaseReducersByName: {},
|
|
1272
1272
|
sliceCaseReducersByType: {},
|
|
@@ -1302,7 +1302,7 @@ function buildCreateSlice({
|
|
|
1302
1302
|
}
|
|
1303
1303
|
};
|
|
1304
1304
|
reducerNames.forEach((reducerName) => {
|
|
1305
|
-
const reducerDefinition =
|
|
1305
|
+
const reducerDefinition = reducers2[reducerName];
|
|
1306
1306
|
const reducerDetails = {
|
|
1307
1307
|
reducerName,
|
|
1308
1308
|
type: getType(name, reducerName),
|
|
@@ -1383,7 +1383,7 @@ function buildCreateSlice({
|
|
|
1383
1383
|
selectSlice
|
|
1384
1384
|
};
|
|
1385
1385
|
}
|
|
1386
|
-
const
|
|
1386
|
+
const slice = {
|
|
1387
1387
|
name,
|
|
1388
1388
|
reducer,
|
|
1389
1389
|
actions: context.actionCreators,
|
|
@@ -1400,12 +1400,12 @@ function buildCreateSlice({
|
|
|
1400
1400
|
reducer
|
|
1401
1401
|
}, config);
|
|
1402
1402
|
return {
|
|
1403
|
-
...
|
|
1403
|
+
...slice,
|
|
1404
1404
|
...makeSelectorProps(newReducerPath, true)
|
|
1405
1405
|
};
|
|
1406
1406
|
}
|
|
1407
1407
|
};
|
|
1408
|
-
return
|
|
1408
|
+
return slice;
|
|
1409
1409
|
};
|
|
1410
1410
|
}
|
|
1411
1411
|
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
@@ -1541,29 +1541,38 @@ function formatProdErrorMessage(code) {
|
|
|
1541
1541
|
}
|
|
1542
1542
|
|
|
1543
1543
|
// src/redux/themeSlice.ts
|
|
1544
|
-
var
|
|
1544
|
+
var defaultInitialState = {
|
|
1545
1545
|
appearance: "system",
|
|
1546
1546
|
color: "#6750a4"
|
|
1547
1547
|
};
|
|
1548
|
-
var
|
|
1548
|
+
var reducers = {
|
|
1549
|
+
initialize: (state, action) => ({ ...state, ...action.payload }),
|
|
1550
|
+
setAppearance: (state, action) => ({ ...state, appearance: action.payload }),
|
|
1551
|
+
setColor: (state, action) => ({ ...state, color: action.payload })
|
|
1552
|
+
};
|
|
1553
|
+
function createThemeReducer(initialState) {
|
|
1554
|
+
return createSlice({
|
|
1555
|
+
name: "theme",
|
|
1556
|
+
initialState: { ...defaultInitialState, ...initialState },
|
|
1557
|
+
reducers
|
|
1558
|
+
}).reducer;
|
|
1559
|
+
}
|
|
1560
|
+
var defaultSlice = createSlice({
|
|
1549
1561
|
name: "theme",
|
|
1550
|
-
initialState,
|
|
1551
|
-
reducers
|
|
1552
|
-
initialize: (state, action) => ({ ...state, ...action.payload }),
|
|
1553
|
-
setAppearance: (state, action) => ({ ...state, appearance: action.payload }),
|
|
1554
|
-
setColor: (state, action) => ({ ...state, color: action.payload })
|
|
1555
|
-
}
|
|
1562
|
+
initialState: defaultInitialState,
|
|
1563
|
+
reducers
|
|
1556
1564
|
});
|
|
1557
|
-
var themeActions =
|
|
1558
|
-
var themeReducer =
|
|
1565
|
+
var themeActions = defaultSlice.actions;
|
|
1566
|
+
var themeReducer = defaultSlice.reducer;
|
|
1567
|
+
var selectThemeAppearance = (state) => state.appearance;
|
|
1568
|
+
var selectThemeColor = (state) => state.color;
|
|
1559
1569
|
|
|
1560
1570
|
// src/ThemeProvider.tsx
|
|
1561
|
-
import
|
|
1571
|
+
import { useEffect as useEffect2, useRef } from "react";
|
|
1562
1572
|
import { StatusBar, StyleSheet, View } from "react-native";
|
|
1563
1573
|
import { Provider as PaperProvider } from "react-native-paper";
|
|
1564
1574
|
|
|
1565
1575
|
// src/useComputedTheme.ts
|
|
1566
|
-
import * as SplashScreen from "expo-splash-screen";
|
|
1567
1576
|
import { useCallback, useEffect, useState } from "react";
|
|
1568
1577
|
import { Appearance } from "react-native";
|
|
1569
1578
|
import { MD3DarkTheme, MD3LightTheme } from "react-native-paper";
|
|
@@ -1876,8 +1885,7 @@ var isDarkColor = (value) => {
|
|
|
1876
1885
|
};
|
|
1877
1886
|
|
|
1878
1887
|
// src/useComputedTheme.ts
|
|
1879
|
-
function useComputedTheme(appearance, color
|
|
1880
|
-
const splashScreen = options?.splashScreen !== false;
|
|
1888
|
+
function useComputedTheme(appearance, color) {
|
|
1881
1889
|
const [theme, setTheme] = useState(null);
|
|
1882
1890
|
const computeTheme = useCallback(() => {
|
|
1883
1891
|
let resolved = appearance;
|
|
@@ -1929,38 +1937,35 @@ function useComputedTheme(appearance, color, options) {
|
|
|
1929
1937
|
const subscription = Appearance.addChangeListener(computeTheme);
|
|
1930
1938
|
return subscription.remove;
|
|
1931
1939
|
}, [computeTheme]);
|
|
1932
|
-
useEffect(() => {
|
|
1933
|
-
if (theme && splashScreen) SplashScreen.hideAsync();
|
|
1934
|
-
}, [theme, splashScreen]);
|
|
1935
1940
|
return theme;
|
|
1936
1941
|
}
|
|
1937
1942
|
|
|
1938
1943
|
// src/ThemeProvider.tsx
|
|
1939
|
-
function
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
}
|
|
1948
|
-
function ThemeProvider({ appearance, color, splashScreen = true, children }) {
|
|
1949
|
-
const theme = useComputedTheme(appearance, color, { splashScreen });
|
|
1944
|
+
function Provider({ appearance, color, children, onReady, statusBarProps, style }) {
|
|
1945
|
+
const theme = useComputedTheme(appearance, color);
|
|
1946
|
+
const called = useRef(false);
|
|
1947
|
+
useEffect2(() => {
|
|
1948
|
+
if (theme && !called.current) {
|
|
1949
|
+
called.current = true;
|
|
1950
|
+
onReady?.();
|
|
1951
|
+
}
|
|
1952
|
+
}, [theme, onReady]);
|
|
1950
1953
|
if (!theme) return null;
|
|
1951
|
-
return /* @__PURE__ */ React.createElement(PaperProvider, { theme }, /* @__PURE__ */ React.createElement(StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content" }), /* @__PURE__ */ React.createElement(View, { style: styles.flex }, children));
|
|
1954
|
+
return /* @__PURE__ */ React.createElement(PaperProvider, { theme }, /* @__PURE__ */ React.createElement(StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content", ...statusBarProps }), /* @__PURE__ */ React.createElement(View, { style: [styles.flex, { backgroundColor: theme.colors.background }, style] }, children));
|
|
1952
1955
|
}
|
|
1953
1956
|
var styles = StyleSheet.create({
|
|
1954
1957
|
flex: { flex: 1 }
|
|
1955
1958
|
});
|
|
1956
1959
|
export {
|
|
1957
|
-
|
|
1958
|
-
|
|
1960
|
+
Provider,
|
|
1961
|
+
createThemeReducer,
|
|
1959
1962
|
getBlendedColor,
|
|
1960
1963
|
getHex,
|
|
1961
1964
|
getRgb,
|
|
1962
1965
|
getTriadicPalette,
|
|
1963
1966
|
isDarkColor,
|
|
1967
|
+
selectThemeAppearance,
|
|
1968
|
+
selectThemeColor,
|
|
1964
1969
|
themeActions,
|
|
1965
1970
|
themeReducer,
|
|
1966
1971
|
useComputedTheme
|
package/package.json
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rific/auto-paper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Adaptive react-native-paper theming: triadic palette from a seed color + system/light/dark appearance",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"expo",
|
|
8
|
+
"react-native-paper",
|
|
9
|
+
"md3",
|
|
10
|
+
"material-you",
|
|
11
|
+
"material-design",
|
|
12
|
+
"theming",
|
|
13
|
+
"dark-mode",
|
|
14
|
+
"seed-color",
|
|
15
|
+
"color-palette",
|
|
16
|
+
"triadic",
|
|
17
|
+
"adaptive-theme",
|
|
18
|
+
"appearance"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/jayrdeaton/react-native-auto-paper#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/jayrdeaton/react-native-auto-paper/issues"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/jayrdeaton/react-native-auto-paper.git"
|
|
10
27
|
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Jay Deaton",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"type": "commonjs",
|
|
11
32
|
"exports": {
|
|
12
33
|
".": {
|
|
13
34
|
"types": "./dist/index.d.ts",
|
|
@@ -15,69 +36,62 @@
|
|
|
15
36
|
"require": "./dist/index.js"
|
|
16
37
|
}
|
|
17
38
|
},
|
|
39
|
+
"main": "dist/index.js",
|
|
40
|
+
"module": "dist/index.mjs",
|
|
41
|
+
"types": "dist/index.d.ts",
|
|
18
42
|
"files": [
|
|
19
43
|
"dist"
|
|
20
44
|
],
|
|
21
45
|
"scripts": {
|
|
22
46
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
47
|
+
"fix": "eslint --fix",
|
|
48
|
+
"lint": "eslint",
|
|
49
|
+
"prepublishOnly": "npm run build",
|
|
50
|
+
"release": "git push --follow-tags",
|
|
51
|
+
"release:major": "npm version major && git push --follow-tags",
|
|
52
|
+
"release:minor": "npm version minor && git push --follow-tags",
|
|
53
|
+
"release:patch": "npm version patch && git push --follow-tags",
|
|
26
54
|
"test": "jest",
|
|
27
55
|
"test:watch": "jest --watchAll",
|
|
28
|
-
"
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
29
57
|
"preversion": "npm run lint && npm test"
|
|
30
58
|
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"expo-splash-screen": ">=0.26.0",
|
|
33
|
-
"react": ">=18.0.0",
|
|
34
|
-
"react-native": ">=0.73.0",
|
|
35
|
-
"react-native-paper": ">=5.0.0"
|
|
36
|
-
},
|
|
37
|
-
"peerDependenciesMeta": {
|
|
38
|
-
"expo-splash-screen": {
|
|
39
|
-
"optional": true
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
59
|
"devDependencies": {
|
|
43
60
|
"@reduxjs/toolkit": "^2.0.0",
|
|
44
61
|
"@testing-library/dom": "^10.4.1",
|
|
45
62
|
"@testing-library/react": "^16.0.0",
|
|
46
|
-
"@types/jest": "^
|
|
47
|
-
"@types/react": "^
|
|
63
|
+
"@types/jest": "^30.0.0",
|
|
64
|
+
"@types/react": "^19.0.0",
|
|
48
65
|
"@types/react-native": "^0.73.0",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^8.59.3",
|
|
50
66
|
"@typescript-eslint/parser": "^8.59.3",
|
|
51
67
|
"eslint": "^9.39.4",
|
|
52
68
|
"eslint-config-prettier": "^10.1.8",
|
|
69
|
+
"eslint-plugin-package-json": "^1.0.0",
|
|
53
70
|
"eslint-plugin-prettier": "^5.5.5",
|
|
54
71
|
"eslint-plugin-react-native": "^5.0.0",
|
|
55
72
|
"eslint-plugin-simple-import-sort": "^13.0.0",
|
|
56
|
-
"
|
|
57
|
-
"jest": "^
|
|
58
|
-
"jest-environment-jsdom": "^29.0.0",
|
|
73
|
+
"jest": "^30.0.0",
|
|
74
|
+
"jest-environment-jsdom": "^30.0.0",
|
|
59
75
|
"prettier": "^3.8.3",
|
|
60
|
-
"react": "^
|
|
61
|
-
"react-dom": "^
|
|
76
|
+
"react": "^19.0.0",
|
|
77
|
+
"react-dom": "^19.0.0",
|
|
62
78
|
"react-native": "^0.76.0",
|
|
63
79
|
"react-native-paper": "^5.12.0",
|
|
64
|
-
"ts-jest": "^29.
|
|
80
|
+
"ts-jest": "^29.4.9",
|
|
81
|
+
"ts-node": "^10.9.2",
|
|
65
82
|
"tsup": "^8.0.0",
|
|
66
83
|
"typescript": "^5.0.0",
|
|
67
84
|
"typescript-eslint": "^8.59.3"
|
|
68
85
|
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": ">=18.0.0",
|
|
88
|
+
"react-native": ">=0.73.0",
|
|
89
|
+
"react-native-paper": ">=5.0.0"
|
|
90
|
+
},
|
|
69
91
|
"optionalDependencies": {
|
|
70
92
|
"@reduxjs/toolkit": "^2.0.0"
|
|
71
93
|
},
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
"theme",
|
|
76
|
-
"material-design",
|
|
77
|
-
"adaptive",
|
|
78
|
-
"dark-mode",
|
|
79
|
-
"color-palette",
|
|
80
|
-
"triadic"
|
|
81
|
-
],
|
|
82
|
-
"license": "MIT"
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public"
|
|
96
|
+
}
|
|
83
97
|
}
|