@rific/auto-paper 0.10.3 → 0.12.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/dist/index.js CHANGED
@@ -76,15 +76,16 @@ __export(index_exports, {
76
76
  useNavBarContext: () => useNavBarContext,
77
77
  usePaperDefaults: () => usePaperDefaults,
78
78
  useReanimatedModule: () => useReanimatedModule,
79
+ useThemeBridgeProps: () => useThemeBridgeProps,
79
80
  useThemeSettings: () => useThemeSettings
80
81
  });
81
82
  module.exports = __toCommonJS(index_exports);
82
83
 
83
84
  // src/BlurContext.tsx
84
- var import_react2 = require("react");
85
+ var import_react = require("react");
85
86
 
86
87
  // src/ThemeSettingsContext.ts
87
- var import_react = require("react");
88
+ var import_core = require("@rific/core");
88
89
  var defaultThemeSettings = {
89
90
  appearance: "system",
90
91
  blur: true,
@@ -92,15 +93,14 @@ var defaultThemeSettings = {
92
93
  color: "#6750a4",
93
94
  harmony: "split-complementary"
94
95
  };
95
- var ThemeSettingsContext = (0, import_react.createContext)({
96
- settings: defaultThemeSettings,
97
- set: () => {
98
- }
99
- });
96
+ var themeSettingsContext = (0, import_core.createSettingsContext)(defaultThemeSettings);
97
+ var ThemeSettingsContext = themeSettingsContext.Context;
98
+ var themeSettingsProvider = themeSettingsContext.Provider;
99
+ var useThemeSettingsInternal = themeSettingsContext.useSettings;
100
100
 
101
101
  // src/BlurContext.tsx
102
102
  function useBlur(override) {
103
- const { settings } = (0, import_react2.useContext)(ThemeSettingsContext);
103
+ const { settings } = (0, import_react.useContext)(ThemeSettingsContext);
104
104
  return override ?? settings.blur;
105
105
  }
106
106
 
@@ -109,10 +109,10 @@ var import_react_native = require("react-native");
109
109
  var import_react_native_paper = require("react-native-paper");
110
110
 
111
111
  // src/PaperDefaultsContext.tsx
112
- var import_react3 = require("react");
113
- var PaperDefaultsContext = (0, import_react3.createContext)({});
112
+ var import_react2 = require("react");
113
+ var PaperDefaultsContext = (0, import_react2.createContext)({});
114
114
  function usePaperDefaults() {
115
- return (0, import_react3.useContext)(PaperDefaultsContext);
115
+ return (0, import_react2.useContext)(PaperDefaultsContext);
116
116
  }
117
117
 
118
118
  // src/components/Appbar.tsx
@@ -151,8 +151,7 @@ var AppearancePicker = ({ value, onChange, showLabels = true, icons }) => {
151
151
  };
152
152
 
153
153
  // src/useThemeSettings.ts
154
- var import_react4 = require("react");
155
- var useThemeSettings = () => (0, import_react4.useContext)(ThemeSettingsContext);
154
+ var useThemeSettings = useThemeSettingsInternal;
156
155
 
157
156
  // src/components/AutoAppearancePicker.tsx
158
157
  var import_jsx_runtime3 = require("react/jsx-runtime");
@@ -165,16 +164,16 @@ var AutoAppearancePicker = (props) => {
165
164
  var resolveSeedColor = (color) => typeof color === "string" ? color : color.primary;
166
165
 
167
166
  // src/components/PalettePicker.tsx
168
- var import_react11 = require("react");
167
+ var import_react9 = require("react");
169
168
  var import_react_native7 = require("react-native");
170
169
  var import_react_native_paper9 = require("react-native-paper");
171
170
 
172
171
  // src/useSwatchGrid.ts
173
- var import_react5 = require("react");
172
+ var import_react3 = require("react");
174
173
  var SWATCH_GRID_COLUMNS = 5;
175
174
  var SWATCH_GRID_GAP = 12;
176
175
  function useSwatchSize(fallback) {
177
- const [width, setWidth] = (0, import_react5.useState)(0);
176
+ const [width, setWidth] = (0, import_react3.useState)(0);
178
177
  const onLayout = ({ nativeEvent }) => setWidth(nativeEvent.layout.width);
179
178
  const size = width > 0 ? (width - SWATCH_GRID_GAP * (SWATCH_GRID_COLUMNS - 1)) / SWATCH_GRID_COLUMNS : fallback;
180
179
  return { onLayout, size };
@@ -494,23 +493,23 @@ function hslToHex(h, s, l) {
494
493
  }
495
494
 
496
495
  // src/components/ColorPicker.tsx
497
- var import_react10 = require("react");
496
+ var import_react8 = require("react");
498
497
  var import_react_native6 = require("react-native");
499
498
  var import_react_native_paper7 = require("react-native-paper");
500
499
 
501
500
  // src/components/Dialog.tsx
502
- var import_react9 = __toESM(require("react"));
501
+ var import_react7 = __toESM(require("react"));
503
502
  var import_react_native5 = require("react-native");
504
503
  var import_react_native_paper6 = require("react-native-paper");
505
504
  var import_react_native_safe_area_context = require("react-native-safe-area-context");
506
505
 
507
506
  // src/ThemeProvider.tsx
508
- var import_react7 = require("react");
507
+ var import_react5 = require("react");
509
508
  var import_react_native3 = require("react-native");
510
509
  var import_react_native_paper4 = require("react-native-paper");
511
510
 
512
511
  // src/useComputedTheme.ts
513
- var import_react6 = require("react");
512
+ var import_react4 = require("react");
514
513
  var import_react_native2 = require("react-native");
515
514
  var import_react_native_paper3 = require("react-native-paper");
516
515
 
@@ -601,11 +600,11 @@ var SEMANTIC_BASE_COLORS = {
601
600
  danger: "#B00020"
602
601
  };
603
602
  function useComputedTheme(appearance, color, harmony = "split-complementary") {
604
- const [theme, setTheme] = (0, import_react6.useState)(null);
603
+ const [theme, setTheme] = (0, import_react4.useState)(null);
605
604
  const primaryInput = typeof color === "string" ? color : color.primary;
606
605
  const secondaryInput = typeof color === "string" ? null : color.secondary;
607
606
  const tertiaryInput = typeof color === "string" ? null : color.tertiary;
608
- const computeTheme = (0, import_react6.useCallback)(() => {
607
+ const computeTheme = (0, import_react4.useCallback)(() => {
609
608
  let resolved = appearance;
610
609
  if (resolved === "system") resolved = import_react_native2.Appearance.getColorScheme();
611
610
  if (resolved === "no-preference" || !resolved) resolved = "light";
@@ -667,10 +666,10 @@ function useComputedTheme(appearance, color, harmony = "split-complementary") {
667
666
  };
668
667
  setTheme(_theme);
669
668
  }, [appearance, primaryInput, secondaryInput, tertiaryInput, harmony]);
670
- (0, import_react6.useEffect)(() => {
669
+ (0, import_react4.useEffect)(() => {
671
670
  computeTheme();
672
671
  }, [computeTheme]);
673
- (0, import_react6.useEffect)(() => {
672
+ (0, import_react4.useEffect)(() => {
674
673
  const subscription = import_react_native2.Appearance.addChangeListener(computeTheme);
675
674
  return subscription.remove;
676
675
  }, [computeTheme]);
@@ -679,53 +678,43 @@ function useComputedTheme(appearance, color, harmony = "split-complementary") {
679
678
 
680
679
  // src/ThemeProvider.tsx
681
680
  var import_jsx_runtime4 = require("react/jsx-runtime");
682
- var NavBarContext = (0, import_react7.createContext)({});
683
- var useNavBarContext = () => (0, import_react7.useContext)(NavBarContext);
684
- var BlurModuleContext = (0, import_react7.createContext)(void 0);
685
- var useBlurModule = () => (0, import_react7.useContext)(BlurModuleContext);
686
- var ReanimatedModuleContext = (0, import_react7.createContext)(void 0);
687
- var useReanimatedModule = () => (0, import_react7.useContext)(ReanimatedModuleContext);
681
+ var NavBarContext = (0, import_react5.createContext)({});
682
+ var useNavBarContext = () => (0, import_react5.useContext)(NavBarContext);
683
+ var BlurModuleContext = (0, import_react5.createContext)(void 0);
684
+ var useBlurModule = () => (0, import_react5.useContext)(BlurModuleContext);
685
+ var ReanimatedModuleContext = (0, import_react5.createContext)(void 0);
686
+ var useReanimatedModule = () => (0, import_react5.useContext)(ReanimatedModuleContext);
688
687
  function Provider({ children, defaults, expoBlur, fontFamily, initialValue, navigationBar, onChange, onNavBarChange, onReady, reanimated, statusBarProps, style }) {
689
- const [settings, setSettings] = (0, import_react7.useState)(() => ({ ...defaultThemeSettings, ...initialValue }));
690
- const set = (0, import_react7.useCallback)((patch) => {
691
- setSettings((prev) => ({ ...prev, ...patch }));
692
- }, []);
693
- const onChangeRef = (0, import_react7.useRef)(onChange);
694
- (0, import_react7.useEffect)(() => {
695
- onChangeRef.current = onChange;
696
- });
697
- const prevSettings = (0, import_react7.useRef)(settings);
698
- (0, import_react7.useEffect)(() => {
699
- if (prevSettings.current !== settings) {
700
- prevSettings.current = settings;
701
- onChangeRef.current?.(settings);
702
- }
703
- }, [settings]);
688
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ThemeSettingsProvider, { initialValue, onChange, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ThemeProviderBody, { defaults, expoBlur, fontFamily, navigationBar, onNavBarChange, onReady, reanimated, statusBarProps, style, children }) });
689
+ }
690
+ var ThemeSettingsProvider = themeSettingsProvider;
691
+ function ThemeProviderBody({ children, defaults, expoBlur, fontFamily, navigationBar, onNavBarChange, onReady, reanimated, statusBarProps, style }) {
692
+ const { settings } = useThemeSettingsInternal();
704
693
  const computedTheme = useComputedTheme(settings.appearance, settings.color, settings.harmony);
705
- const theme = (0, import_react7.useMemo)(() => {
694
+ const theme = (0, import_react5.useMemo)(() => {
706
695
  if (!computedTheme) return null;
707
696
  if (!fontFamily) return computedTheme;
708
697
  return { ...computedTheme, fonts: (0, import_react_native_paper4.configureFonts)({ config: { fontFamily } }) };
709
698
  }, [computedTheme, fontFamily]);
710
- const called = (0, import_react7.useRef)(false);
711
- (0, import_react7.useEffect)(() => {
699
+ const called = (0, import_react5.useRef)(false);
700
+ (0, import_react5.useEffect)(() => {
712
701
  if (theme && !called.current) {
713
702
  called.current = true;
714
703
  onReady?.();
715
704
  }
716
705
  }, [theme, onReady]);
717
706
  if (!theme) return null;
718
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ThemeSettingsContext.Provider, { value: { settings, set }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native_paper4.Provider, { theme, children: [
707
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native_paper4.Provider, { theme, children: [
719
708
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content", ...statusBarProps }),
720
709
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PaperDefaultsContext.Provider, { value: defaults ?? {}, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NavBarContext.Provider, { value: { navigationBar, onNavBarChange }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BlurModuleContext.Provider, { value: expoBlur, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ReanimatedModuleContext.Provider, { value: reanimated, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: [styles.flex, { backgroundColor: theme.colors.background }, style], children }) }) }) }) })
721
- ] }) });
710
+ ] });
722
711
  }
723
712
  var styles = import_react_native3.StyleSheet.create({
724
713
  flex: { flex: 1 }
725
714
  });
726
715
 
727
716
  // src/components/BlurView.tsx
728
- var import_react8 = require("react");
717
+ var import_react6 = require("react");
729
718
  var import_react_native4 = require("react-native");
730
719
  var import_react_native_paper5 = require("react-native-paper");
731
720
  var import_jsx_runtime5 = require("react/jsx-runtime");
@@ -733,7 +722,7 @@ var ELEVATION_OPACITY = { 0: 0, 1: 0.05, 2: 0.08, 3: 0.11, 4: 0.12, 5: 0.14 };
733
722
  var VARIANT_TINT_OPACITY = { light: 0.12, dark: 0.18 };
734
723
  var BlurView = ({ blur = true, children, elevation, style, tintColor, tintOpacity, variant = "surface", ...props }) => {
735
724
  const { dark, colors } = (0, import_react_native_paper5.useTheme)();
736
- const { settings } = (0, import_react8.useContext)(ThemeSettingsContext);
725
+ const { settings } = (0, import_react6.useContext)(ThemeSettingsContext);
737
726
  const expoBlur = useBlurModule();
738
727
  const surfaceColor = variant === "surfaceVariant" ? colors.surfaceVariant : colors.surface;
739
728
  const variantColor = variant === "primary" ? colors.primary : variant === "secondary" ? colors.secondary : variant === "tertiary" ? colors.tertiary : variant === "error" ? colors.error : void 0;
@@ -763,12 +752,12 @@ function DialogComponent({ animatedStyle, blur: blurProp, dismissable = true, di
763
752
  const { colors, isV3, roundness } = theme;
764
753
  const { scale } = theme.animation;
765
754
  const { bottom, left, right, top } = (0, import_react_native_safe_area_context.useSafeAreaInsets)();
766
- const [opacity] = (0, import_react9.useState)(() => new import_react_native5.Animated.Value(visible ? 1 : 0));
767
- const [mounted, setMounted] = (0, import_react9.useState)(visible);
755
+ const [opacity] = (0, import_react7.useState)(() => new import_react_native5.Animated.Value(visible ? 1 : 0));
756
+ const [mounted, setMounted] = (0, import_react7.useState)(visible);
768
757
  if (visible && !mounted) {
769
758
  setMounted(true);
770
759
  }
771
- (0, import_react9.useEffect)(() => {
760
+ (0, import_react7.useEffect)(() => {
772
761
  if (visible) {
773
762
  import_react_native5.Animated.timing(opacity, { duration: scale * ANIMATION_DURATION, easing: import_react_native5.Easing.out(import_react_native5.Easing.cubic), toValue: 1, useNativeDriver: true }).start();
774
763
  } else {
@@ -777,7 +766,7 @@ function DialogComponent({ animatedStyle, blur: blurProp, dismissable = true, di
777
766
  });
778
767
  }
779
768
  }, [visible, opacity, scale]);
780
- (0, import_react9.useEffect)(() => {
769
+ (0, import_react7.useEffect)(() => {
781
770
  if (!visible) return void 0;
782
771
  const onHardwareBackPress = () => {
783
772
  if (dismissable || dismissableBackButton) onDismiss?.();
@@ -787,14 +776,14 @@ function DialogComponent({ animatedStyle, blur: blurProp, dismissable = true, di
787
776
  return () => subscription.remove();
788
777
  }, [dismissable, dismissableBackButton, onDismiss, visible]);
789
778
  if (!mounted) return null;
790
- const content = import_react9.default.Children.toArray(children).filter((child) => child != null && typeof child !== "boolean").map((child, i) => {
779
+ const content = import_react7.default.Children.toArray(children).filter((child) => child != null && typeof child !== "boolean").map((child, i) => {
791
780
  if (isV3) {
792
- if (i === 0 && import_react9.default.isValidElement(child) && child.type === import_react_native_paper6.Dialog.Content) {
793
- return import_react9.default.cloneElement(child, { style: [{ marginTop: 24 }, child.props.style] });
781
+ if (i === 0 && import_react7.default.isValidElement(child) && child.type === import_react_native_paper6.Dialog.Content) {
782
+ return import_react7.default.cloneElement(child, { style: [{ marginTop: 24 }, child.props.style] });
794
783
  }
795
784
  }
796
- if (i === 0 && import_react9.default.isValidElement(child) && child.type === import_react_native_paper6.Dialog.Content) {
797
- return import_react9.default.cloneElement(child, { style: [{ paddingTop: 24 }, child.props.style] });
785
+ if (i === 0 && import_react7.default.isValidElement(child) && child.type === import_react_native_paper6.Dialog.Content) {
786
+ return import_react7.default.cloneElement(child, { style: [{ paddingTop: 24 }, child.props.style] });
798
787
  }
799
788
  return child;
800
789
  });
@@ -843,7 +832,7 @@ var defaultColors = [
843
832
  var ColorPicker = ({ value, onChange, colors = defaultColors, blur: blurProp }) => {
844
833
  const blur = useBlur(blurProp);
845
834
  const { colors: themeColors } = (0, import_react_native_paper7.useTheme)();
846
- const [open, setOpen] = (0, import_react10.useState)(false);
835
+ const [open, setOpen] = (0, import_react8.useState)(false);
847
836
  const { onLayout, size } = useSwatchSize(SIZE);
848
837
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
849
838
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native_paper7.TouchableRipple, { onPress: () => setOpen(true), style: [styles3.trigger, { backgroundColor: value }, getSwatchRing(value, false, themeColors.outlineVariant)], borderless: true, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native_paper7.Icon, { source: "palette", size: 20, color: getContrastColor(value) }) }),
@@ -919,7 +908,7 @@ var Pie = ({ palette, weights = defaultWeights, size = SIZE2 }) => /* @__PURE__
919
908
  var PalettePicker = ({ value, onChange, harmony = "split-complementary", onHarmonyChange, weights, colors = defaultColors, blur: blurProp }) => {
920
909
  const blur = useBlur(blurProp);
921
910
  const { colors: themeColors } = (0, import_react_native_paper9.useTheme)();
922
- const [open, setOpen] = (0, import_react11.useState)(false);
911
+ const [open, setOpen] = (0, import_react9.useState)(false);
923
912
  const { onLayout, size } = useSwatchSize(SIZE2);
924
913
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
925
914
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_native_paper9.TouchableRipple, { onPress: () => setOpen(true), style: styles4.trigger, borderless: true, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_native7.View, { style: styles4.triggerContent, children: [
@@ -951,8 +940,8 @@ var styles4 = import_react_native7.StyleSheet.create({
951
940
  harmonyRow: { marginBottom: 4 },
952
941
  innerRotator: { height: "100%", left: "-100%", overflow: "hidden", position: "absolute", top: 0, width: "200%" },
953
942
  pie: { overflow: "hidden" },
954
- rotator: { height: "100%", left: 0, overflow: "hidden", position: "absolute", top: 0, width: "100%" },
955
943
  ring: { alignItems: "center", bottom: 0, justifyContent: "center", left: 0, position: "absolute", right: 0, top: 0 },
944
+ rotator: { height: "100%", left: 0, overflow: "hidden", position: "absolute", top: 0, width: "100%" },
956
945
  swatch: { alignItems: "center", justifyContent: "center" },
957
946
  swatches: { flexDirection: "row", flexWrap: "wrap", gap: SWATCH_GRID_GAP, paddingTop: 12 },
958
947
  trigger: { alignItems: "center", alignSelf: "flex-start", borderRadius: SIZE2 / 2, height: SIZE2, justifyContent: "center", width: SIZE2 },
@@ -969,7 +958,7 @@ var AutoPalettePicker = (props) => {
969
958
  };
970
959
 
971
960
  // src/components/BottomNavigation.tsx
972
- var import_react12 = require("react");
961
+ var import_react10 = require("react");
973
962
  var import_react_native8 = require("react-native");
974
963
  var import_react_native_paper10 = require("react-native-paper");
975
964
 
@@ -984,7 +973,7 @@ var import_jsx_runtime11 = require("react/jsx-runtime");
984
973
  function useNavigationBarSync() {
985
974
  const theme = (0, import_react_native_paper10.useTheme)();
986
975
  const { navigationBar, onNavBarChange } = useNavBarContext();
987
- (0, import_react12.useEffect)(() => {
976
+ (0, import_react10.useEffect)(() => {
988
977
  if (import_react_native8.Platform.OS !== "android") return;
989
978
  if (onNavBarChange) onNavBarChange(theme.colors.surface, theme.dark);
990
979
  else if (navigationBar) setNavigationBarStyle(navigationBar, theme.dark);
@@ -1057,55 +1046,46 @@ var styles5 = import_react_native9.StyleSheet.create({
1057
1046
  });
1058
1047
 
1059
1048
  // src/components/TextInput.tsx
1060
- var import_react13 = require("react");
1049
+ var import_react11 = require("react");
1061
1050
  var import_react_native_paper16 = require("react-native-paper");
1062
1051
  var import_jsx_runtime17 = require("react/jsx-runtime");
1063
- var TextInput = (0, import_react13.forwardRef)(function TextInput2(props, ref) {
1052
+ var TextInput = (0, import_react11.forwardRef)(function TextInput2(props, ref) {
1064
1053
  const defaults = usePaperDefaults();
1065
1054
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native_paper16.TextInput, { ref, ...defaults.TextInput, ...props });
1066
1055
  });
1067
1056
 
1068
1057
  // src/redux/themeSlice.ts
1058
+ var import_core2 = require("@rific/core");
1069
1059
  var defaultInitialState = {
1070
1060
  appearance: "system",
1071
1061
  blur: true,
1072
1062
  color: "#6750a4",
1073
1063
  harmony: "split-complementary"
1074
1064
  };
1075
- var createAction = (type) => {
1076
- const actionCreator = (payload) => ({ payload, type });
1077
- actionCreator.type = type;
1078
- actionCreator.match = (action) => action.type === type;
1079
- return actionCreator;
1080
- };
1081
- var initialize = createAction("theme/initialize");
1082
- var setAppearance = createAction("theme/setAppearance");
1083
- var setBlur = createAction("theme/setBlur");
1084
- var setColor = createAction("theme/setColor");
1085
- var setHarmony = createAction("theme/setHarmony");
1086
- var themeActions = { initialize, setAppearance, setBlur, setColor, setHarmony };
1087
- var reduce = (state, action) => {
1088
- if (initialize.match(action)) return { ...state, ...action.payload };
1089
- if (setAppearance.match(action)) return { ...state, appearance: action.payload };
1090
- if (setBlur.match(action)) return { ...state, blur: action.payload };
1091
- if (setColor.match(action)) return { ...state, color: action.payload };
1092
- if (setHarmony.match(action)) return { ...state, harmony: action.payload };
1093
- return state;
1094
- };
1095
- function createThemeReducer(initialState) {
1096
- const initial = { ...defaultInitialState, ...initialState };
1097
- return (state = initial, action) => reduce(state, action);
1098
- }
1099
- var themeReducer = (state = defaultInitialState, action) => reduce(state, action);
1100
- var selectThemeAppearance = (state) => state.appearance;
1101
- var selectThemeBlur = (state) => state.blur;
1102
- var selectThemeColor = (state) => state.color;
1103
- var selectThemeHarmony = (state) => state.harmony;
1065
+ var themeSlice = (0, import_core2.createSettingsSlice)("theme", {
1066
+ initialState: defaultInitialState,
1067
+ initializeMode: "merge",
1068
+ selectors: ["appearance", "blur", "color", "harmony"]
1069
+ });
1070
+ var themeActions = themeSlice.actions;
1071
+ var themeReducer = themeSlice.reducer;
1072
+ var createThemeReducer = themeSlice.createReducer;
1073
+ var selectThemeAppearance = themeSlice.selectors.selectAppearance;
1074
+ var selectThemeBlur = themeSlice.selectors.selectBlur;
1075
+ var selectThemeColor = themeSlice.selectors.selectColor;
1076
+ var selectThemeHarmony = themeSlice.selectors.selectHarmony;
1104
1077
 
1105
1078
  // src/useTheme.ts
1106
1079
  var import_react_native_paper17 = require("react-native-paper");
1107
1080
  var useAutoPaperTheme = () => (0, import_react_native_paper17.useTheme)();
1108
1081
 
1082
+ // src/useThemeBridgeProps.ts
1083
+ var import_react12 = require("react");
1084
+ function useThemeBridgeProps(props) {
1085
+ const { initialValue, onChange, onReady } = props;
1086
+ return (0, import_react12.useMemo)(() => ({ initialValue, onChange, onReady }), [initialValue, onChange, onReady]);
1087
+ }
1088
+
1109
1089
  // src/utils/getThirdColor.ts
1110
1090
  function rgbToHsl(r, g, b) {
1111
1091
  r /= 255;
@@ -1235,5 +1215,6 @@ var getTintTextColor = (tintColor, backdropColor, tintOpacity) => {
1235
1215
  useNavBarContext,
1236
1216
  usePaperDefaults,
1237
1217
  useReanimatedModule,
1218
+ useThemeBridgeProps,
1238
1219
  useThemeSettings
1239
1220
  });
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { useContext } from "react";
3
3
 
4
4
  // src/ThemeSettingsContext.ts
5
- import { createContext } from "react";
5
+ import { createSettingsContext } from "@rific/core";
6
6
  var defaultThemeSettings = {
7
7
  appearance: "system",
8
8
  blur: true,
@@ -10,11 +10,10 @@ var defaultThemeSettings = {
10
10
  color: "#6750a4",
11
11
  harmony: "split-complementary"
12
12
  };
13
- var ThemeSettingsContext = createContext({
14
- settings: defaultThemeSettings,
15
- set: () => {
16
- }
17
- });
13
+ var themeSettingsContext = createSettingsContext(defaultThemeSettings);
14
+ var ThemeSettingsContext = themeSettingsContext.Context;
15
+ var themeSettingsProvider = themeSettingsContext.Provider;
16
+ var useThemeSettingsInternal = themeSettingsContext.useSettings;
18
17
 
19
18
  // src/BlurContext.tsx
20
19
  function useBlur(override) {
@@ -27,8 +26,8 @@ import { StatusBar } from "react-native";
27
26
  import { Appbar as PaperAppbar, useTheme } from "react-native-paper";
28
27
 
29
28
  // src/PaperDefaultsContext.tsx
30
- import { createContext as createContext2, useContext as useContext2 } from "react";
31
- var PaperDefaultsContext = createContext2({});
29
+ import { createContext, useContext as useContext2 } from "react";
30
+ var PaperDefaultsContext = createContext({});
32
31
  function usePaperDefaults() {
33
32
  return useContext2(PaperDefaultsContext);
34
33
  }
@@ -69,8 +68,7 @@ var AppearancePicker = ({ value, onChange, showLabels = true, icons }) => {
69
68
  };
70
69
 
71
70
  // src/useThemeSettings.ts
72
- import { useContext as useContext3 } from "react";
73
- var useThemeSettings = () => useContext3(ThemeSettingsContext);
71
+ var useThemeSettings = useThemeSettingsInternal;
74
72
 
75
73
  // src/components/AutoAppearancePicker.tsx
76
74
  import { jsx as jsx3 } from "react/jsx-runtime";
@@ -83,7 +81,7 @@ var AutoAppearancePicker = (props) => {
83
81
  var resolveSeedColor = (color) => typeof color === "string" ? color : color.primary;
84
82
 
85
83
  // src/components/PalettePicker.tsx
86
- import { useState as useState6 } from "react";
84
+ import { useState as useState5 } from "react";
87
85
  import { StyleSheet as StyleSheet5, TouchableOpacity as TouchableOpacity2, View as View5 } from "react-native";
88
86
  import { Icon as Icon2, TouchableRipple as TouchableRipple2, useTheme as useTheme5 } from "react-native-paper";
89
87
 
@@ -412,18 +410,18 @@ function hslToHex(h, s, l) {
412
410
  }
413
411
 
414
412
  // src/components/ColorPicker.tsx
415
- import { useState as useState5 } from "react";
413
+ import { useState as useState4 } from "react";
416
414
  import { StyleSheet as StyleSheet4, TouchableOpacity, View as View4 } from "react-native";
417
415
  import { Icon, TouchableRipple, useTheme as useTheme4 } from "react-native-paper";
418
416
 
419
417
  // src/components/Dialog.tsx
420
- import React, { useEffect as useEffect3, useState as useState4 } from "react";
418
+ import React, { useEffect as useEffect3, useState as useState3 } from "react";
421
419
  import { Animated, BackHandler, Easing, Pressable, StyleSheet as StyleSheet3, View as View3 } from "react-native";
422
420
  import { Dialog as PaperDialog, Portal, useTheme as useTheme3 } from "react-native-paper";
423
421
  import { useSafeAreaInsets } from "react-native-safe-area-context";
424
422
 
425
423
  // src/ThemeProvider.tsx
426
- import { createContext as createContext3, useCallback as useCallback2, useContext as useContext4, useEffect as useEffect2, useMemo, useRef, useState as useState3 } from "react";
424
+ import { createContext as createContext2, useContext as useContext3, useEffect as useEffect2, useMemo, useRef } from "react";
427
425
  import { StatusBar as StatusBar2, StyleSheet, View } from "react-native";
428
426
  import { configureFonts, Provider as PaperProvider } from "react-native-paper";
429
427
 
@@ -597,28 +595,18 @@ function useComputedTheme(appearance, color, harmony = "split-complementary") {
597
595
 
598
596
  // src/ThemeProvider.tsx
599
597
  import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
600
- var NavBarContext = createContext3({});
601
- var useNavBarContext = () => useContext4(NavBarContext);
602
- var BlurModuleContext = createContext3(void 0);
603
- var useBlurModule = () => useContext4(BlurModuleContext);
604
- var ReanimatedModuleContext = createContext3(void 0);
605
- var useReanimatedModule = () => useContext4(ReanimatedModuleContext);
598
+ var NavBarContext = createContext2({});
599
+ var useNavBarContext = () => useContext3(NavBarContext);
600
+ var BlurModuleContext = createContext2(void 0);
601
+ var useBlurModule = () => useContext3(BlurModuleContext);
602
+ var ReanimatedModuleContext = createContext2(void 0);
603
+ var useReanimatedModule = () => useContext3(ReanimatedModuleContext);
606
604
  function Provider({ children, defaults, expoBlur, fontFamily, initialValue, navigationBar, onChange, onNavBarChange, onReady, reanimated, statusBarProps, style }) {
607
- const [settings, setSettings] = useState3(() => ({ ...defaultThemeSettings, ...initialValue }));
608
- const set = useCallback2((patch) => {
609
- setSettings((prev) => ({ ...prev, ...patch }));
610
- }, []);
611
- const onChangeRef = useRef(onChange);
612
- useEffect2(() => {
613
- onChangeRef.current = onChange;
614
- });
615
- const prevSettings = useRef(settings);
616
- useEffect2(() => {
617
- if (prevSettings.current !== settings) {
618
- prevSettings.current = settings;
619
- onChangeRef.current?.(settings);
620
- }
621
- }, [settings]);
605
+ return /* @__PURE__ */ jsx4(ThemeSettingsProvider, { initialValue, onChange, children: /* @__PURE__ */ jsx4(ThemeProviderBody, { defaults, expoBlur, fontFamily, navigationBar, onNavBarChange, onReady, reanimated, statusBarProps, style, children }) });
606
+ }
607
+ var ThemeSettingsProvider = themeSettingsProvider;
608
+ function ThemeProviderBody({ children, defaults, expoBlur, fontFamily, navigationBar, onNavBarChange, onReady, reanimated, statusBarProps, style }) {
609
+ const { settings } = useThemeSettingsInternal();
622
610
  const computedTheme = useComputedTheme(settings.appearance, settings.color, settings.harmony);
623
611
  const theme = useMemo(() => {
624
612
  if (!computedTheme) return null;
@@ -633,17 +621,17 @@ function Provider({ children, defaults, expoBlur, fontFamily, initialValue, navi
633
621
  }
634
622
  }, [theme, onReady]);
635
623
  if (!theme) return null;
636
- return /* @__PURE__ */ jsx4(ThemeSettingsContext.Provider, { value: { settings, set }, children: /* @__PURE__ */ jsxs2(PaperProvider, { theme, children: [
624
+ return /* @__PURE__ */ jsxs2(PaperProvider, { theme, children: [
637
625
  /* @__PURE__ */ jsx4(StatusBar2, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content", ...statusBarProps }),
638
626
  /* @__PURE__ */ jsx4(PaperDefaultsContext.Provider, { value: defaults ?? {}, children: /* @__PURE__ */ jsx4(NavBarContext.Provider, { value: { navigationBar, onNavBarChange }, children: /* @__PURE__ */ jsx4(BlurModuleContext.Provider, { value: expoBlur, children: /* @__PURE__ */ jsx4(ReanimatedModuleContext.Provider, { value: reanimated, children: /* @__PURE__ */ jsx4(View, { style: [styles.flex, { backgroundColor: theme.colors.background }, style], children }) }) }) }) })
639
- ] }) });
627
+ ] });
640
628
  }
641
629
  var styles = StyleSheet.create({
642
630
  flex: { flex: 1 }
643
631
  });
644
632
 
645
633
  // src/components/BlurView.tsx
646
- import { useContext as useContext5 } from "react";
634
+ import { useContext as useContext4 } from "react";
647
635
  import { StyleSheet as StyleSheet2, View as View2 } from "react-native";
648
636
  import { useTheme as useTheme2 } from "react-native-paper";
649
637
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
@@ -651,7 +639,7 @@ var ELEVATION_OPACITY = { 0: 0, 1: 0.05, 2: 0.08, 3: 0.11, 4: 0.12, 5: 0.14 };
651
639
  var VARIANT_TINT_OPACITY = { light: 0.12, dark: 0.18 };
652
640
  var BlurView = ({ blur = true, children, elevation, style, tintColor, tintOpacity, variant = "surface", ...props }) => {
653
641
  const { dark, colors } = useTheme2();
654
- const { settings } = useContext5(ThemeSettingsContext);
642
+ const { settings } = useContext4(ThemeSettingsContext);
655
643
  const expoBlur = useBlurModule();
656
644
  const surfaceColor = variant === "surfaceVariant" ? colors.surfaceVariant : colors.surface;
657
645
  const variantColor = variant === "primary" ? colors.primary : variant === "secondary" ? colors.secondary : variant === "tertiary" ? colors.tertiary : variant === "error" ? colors.error : void 0;
@@ -681,8 +669,8 @@ function DialogComponent({ animatedStyle, blur: blurProp, dismissable = true, di
681
669
  const { colors, isV3, roundness } = theme;
682
670
  const { scale } = theme.animation;
683
671
  const { bottom, left, right, top } = useSafeAreaInsets();
684
- const [opacity] = useState4(() => new Animated.Value(visible ? 1 : 0));
685
- const [mounted, setMounted] = useState4(visible);
672
+ const [opacity] = useState3(() => new Animated.Value(visible ? 1 : 0));
673
+ const [mounted, setMounted] = useState3(visible);
686
674
  if (visible && !mounted) {
687
675
  setMounted(true);
688
676
  }
@@ -761,7 +749,7 @@ var defaultColors = [
761
749
  var ColorPicker = ({ value, onChange, colors = defaultColors, blur: blurProp }) => {
762
750
  const blur = useBlur(blurProp);
763
751
  const { colors: themeColors } = useTheme4();
764
- const [open, setOpen] = useState5(false);
752
+ const [open, setOpen] = useState4(false);
765
753
  const { onLayout, size } = useSwatchSize(SIZE);
766
754
  return /* @__PURE__ */ jsxs5(Fragment2, { children: [
767
755
  /* @__PURE__ */ jsx7(TouchableRipple, { onPress: () => setOpen(true), style: [styles3.trigger, { backgroundColor: value }, getSwatchRing(value, false, themeColors.outlineVariant)], borderless: true, children: /* @__PURE__ */ jsx7(Icon, { source: "palette", size: 20, color: getContrastColor(value) }) }),
@@ -837,7 +825,7 @@ var Pie = ({ palette, weights = defaultWeights, size = SIZE2 }) => /* @__PURE__
837
825
  var PalettePicker = ({ value, onChange, harmony = "split-complementary", onHarmonyChange, weights, colors = defaultColors, blur: blurProp }) => {
838
826
  const blur = useBlur(blurProp);
839
827
  const { colors: themeColors } = useTheme5();
840
- const [open, setOpen] = useState6(false);
828
+ const [open, setOpen] = useState5(false);
841
829
  const { onLayout, size } = useSwatchSize(SIZE2);
842
830
  return /* @__PURE__ */ jsxs6(Fragment3, { children: [
843
831
  /* @__PURE__ */ jsx9(TouchableRipple2, { onPress: () => setOpen(true), style: styles4.trigger, borderless: true, children: /* @__PURE__ */ jsxs6(View5, { style: styles4.triggerContent, children: [
@@ -869,8 +857,8 @@ var styles4 = StyleSheet5.create({
869
857
  harmonyRow: { marginBottom: 4 },
870
858
  innerRotator: { height: "100%", left: "-100%", overflow: "hidden", position: "absolute", top: 0, width: "200%" },
871
859
  pie: { overflow: "hidden" },
872
- rotator: { height: "100%", left: 0, overflow: "hidden", position: "absolute", top: 0, width: "100%" },
873
860
  ring: { alignItems: "center", bottom: 0, justifyContent: "center", left: 0, position: "absolute", right: 0, top: 0 },
861
+ rotator: { height: "100%", left: 0, overflow: "hidden", position: "absolute", top: 0, width: "100%" },
874
862
  swatch: { alignItems: "center", justifyContent: "center" },
875
863
  swatches: { flexDirection: "row", flexWrap: "wrap", gap: SWATCH_GRID_GAP, paddingTop: 12 },
876
864
  trigger: { alignItems: "center", alignSelf: "flex-start", borderRadius: SIZE2 / 2, height: SIZE2, justifyContent: "center", width: SIZE2 },
@@ -984,46 +972,37 @@ var TextInput = forwardRef(function TextInput2(props, ref) {
984
972
  });
985
973
 
986
974
  // src/redux/themeSlice.ts
975
+ import { createSettingsSlice } from "@rific/core";
987
976
  var defaultInitialState = {
988
977
  appearance: "system",
989
978
  blur: true,
990
979
  color: "#6750a4",
991
980
  harmony: "split-complementary"
992
981
  };
993
- var createAction = (type) => {
994
- const actionCreator = (payload) => ({ payload, type });
995
- actionCreator.type = type;
996
- actionCreator.match = (action) => action.type === type;
997
- return actionCreator;
998
- };
999
- var initialize = createAction("theme/initialize");
1000
- var setAppearance = createAction("theme/setAppearance");
1001
- var setBlur = createAction("theme/setBlur");
1002
- var setColor = createAction("theme/setColor");
1003
- var setHarmony = createAction("theme/setHarmony");
1004
- var themeActions = { initialize, setAppearance, setBlur, setColor, setHarmony };
1005
- var reduce = (state, action) => {
1006
- if (initialize.match(action)) return { ...state, ...action.payload };
1007
- if (setAppearance.match(action)) return { ...state, appearance: action.payload };
1008
- if (setBlur.match(action)) return { ...state, blur: action.payload };
1009
- if (setColor.match(action)) return { ...state, color: action.payload };
1010
- if (setHarmony.match(action)) return { ...state, harmony: action.payload };
1011
- return state;
1012
- };
1013
- function createThemeReducer(initialState) {
1014
- const initial = { ...defaultInitialState, ...initialState };
1015
- return (state = initial, action) => reduce(state, action);
1016
- }
1017
- var themeReducer = (state = defaultInitialState, action) => reduce(state, action);
1018
- var selectThemeAppearance = (state) => state.appearance;
1019
- var selectThemeBlur = (state) => state.blur;
1020
- var selectThemeColor = (state) => state.color;
1021
- var selectThemeHarmony = (state) => state.harmony;
982
+ var themeSlice = createSettingsSlice("theme", {
983
+ initialState: defaultInitialState,
984
+ initializeMode: "merge",
985
+ selectors: ["appearance", "blur", "color", "harmony"]
986
+ });
987
+ var themeActions = themeSlice.actions;
988
+ var themeReducer = themeSlice.reducer;
989
+ var createThemeReducer = themeSlice.createReducer;
990
+ var selectThemeAppearance = themeSlice.selectors.selectAppearance;
991
+ var selectThemeBlur = themeSlice.selectors.selectBlur;
992
+ var selectThemeColor = themeSlice.selectors.selectColor;
993
+ var selectThemeHarmony = themeSlice.selectors.selectHarmony;
1022
994
 
1023
995
  // src/useTheme.ts
1024
996
  import { useTheme as usePaperTheme } from "react-native-paper";
1025
997
  var useAutoPaperTheme = () => usePaperTheme();
1026
998
 
999
+ // src/useThemeBridgeProps.ts
1000
+ import { useMemo as useMemo2 } from "react";
1001
+ function useThemeBridgeProps(props) {
1002
+ const { initialValue, onChange, onReady } = props;
1003
+ return useMemo2(() => ({ initialValue, onChange, onReady }), [initialValue, onChange, onReady]);
1004
+ }
1005
+
1027
1006
  // src/utils/getThirdColor.ts
1028
1007
  function rgbToHsl(r, g, b) {
1029
1008
  r /= 255;
@@ -1152,5 +1131,6 @@ export {
1152
1131
  useNavBarContext,
1153
1132
  usePaperDefaults,
1154
1133
  useReanimatedModule,
1134
+ useThemeBridgeProps,
1155
1135
  useThemeSettings
1156
1136
  };