@tamagui/core 1.112.9 → 1.112.11

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/native.js CHANGED
@@ -3224,7 +3224,7 @@ var require_ThemeManager_native = __commonJS({
3224
3224
  "use strict";
3225
3225
  function ThemeManager2() {
3226
3226
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, parentManager = arguments.length > 1 ? arguments[1] : void 0;
3227
- if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3227
+ if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), _define_property(this, "_selfListener", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3228
3228
  this.updateStateFromProps(props, !1);
3229
3229
  return;
3230
3230
  }
@@ -3244,11 +3244,22 @@ var require_ThemeManager_native = __commonJS({
3244
3244
  {
3245
3245
  key: "updateState",
3246
3246
  value: function(nextState) {
3247
- var _this = this, shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3248
- this.state = nextState, this._allKeys = null, shouldNotify && this.notify();
3247
+ var shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3248
+ this.state = nextState, this._allKeys = null;
3249
3249
  }
3250
3250
  },
3251
3251
  {
3252
+ // if (shouldNotify) {
3253
+ // if (process.env.TAMAGUI_TARGET === 'native') {
3254
+ // // native is way slower with queueMicrotask
3255
+ // this.notify()
3256
+ // } else {
3257
+ // // web is way faster this way
3258
+ // queueMicrotask(() => {
3259
+ // this.notify()
3260
+ // })
3261
+ // }
3262
+ // }
3252
3263
  key: "getStateIfChanged",
3253
3264
  value: function() {
3254
3265
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.props, state = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.state, parentManager = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : this.parentManager, _ = this.getState(props, parentManager);
@@ -3292,6 +3303,13 @@ var require_ThemeManager_native = __commonJS({
3292
3303
  }
3293
3304
  }
3294
3305
  },
3306
+ {
3307
+ key: "selfUpdate",
3308
+ value: function() {
3309
+ var _this__selfListener, _this;
3310
+ (_this__selfListener = (_this = this)._selfListener) === null || _this__selfListener === void 0 || _this__selfListener.call(_this, this.state.name, this, "self");
3311
+ }
3312
+ },
3295
3313
  {
3296
3314
  key: "onChangeTheme",
3297
3315
  value: function(cb, debugId) {
@@ -3300,7 +3318,7 @@ var require_ThemeManager_native = __commonJS({
3300
3318
  var _this__listeningIds;
3301
3319
  (_this__listeningIds = this._listeningIds) !== null && _this__listeningIds !== void 0 || (this._listeningIds = /* @__PURE__ */ new Set()), this._listeningIds.add(debugId);
3302
3320
  }
3303
- return this.themeListeners.add(cb), function() {
3321
+ return debugId === !0 && (this._selfListener = cb), this.themeListeners.add(cb), function() {
3304
3322
  _this.themeListeners.delete(cb);
3305
3323
  };
3306
3324
  }
@@ -3659,7 +3677,7 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3659
3677
  if (!theme) return {};
3660
3678
  var config = (0, import_config.getConfig)();
3661
3679
  function track(key) {
3662
- keys && !keys.includes(key) && (keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
3680
+ keys && !keys.includes(key) && (keys.length || themeManager == null || themeManager.selfUpdate(), keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
3663
3681
  }
3664
3682
  return new Proxy(theme, {
3665
3683
  has(_, key) {
@@ -3735,15 +3753,19 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3735
3753
  state: parentManager == null ? void 0 : parentManager.state,
3736
3754
  themeManager: parentManager
3737
3755
  };
3738
- var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3756
+ var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed, prevState } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3739
3757
  function getShouldUpdateTheme() {
3740
- var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3758
+ var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3741
3759
  if (!(!manager || !forceShouldChange && forceUpdate === !1)) {
3742
3760
  var next = nextState || manager.getState(props, parentManager);
3743
- if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState))) return next;
3761
+ if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState2))) return next;
3744
3762
  }
3745
3763
  }
3746
- if (import_constants2.isServer || (import_react3.default.useEffect(function() {
3764
+ if (import_constants2.isServer || (import_react3.default.useLayoutEffect(function() {
3765
+ themeManager && state && prevState && state !== prevState && themeManager.notify();
3766
+ }, [
3767
+ state
3768
+ ]), import_react3.default.useEffect(function() {
3747
3769
  if (themeManager) {
3748
3770
  if (props.inverse && !mounted) {
3749
3771
  setThemeState(function(prev) {
@@ -3756,10 +3778,11 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3756
3778
  }
3757
3779
  (isNewTheme || getShouldUpdateTheme(themeManager)) && (activeThemeManagers.add(themeManager), setThemeState(createState));
3758
3780
  var selfListenerDispose = themeManager.onChangeTheme(function(_a, _b, forced) {
3759
- forced && (console.error = preventWarnSetState, setThemeState(function(prev) {
3760
- return createState(prev, !0);
3761
- }), console.error = ogLog);
3762
- }), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3781
+ forced && setThemeState(function(prev) {
3782
+ var next = createState(prev, forced !== "self");
3783
+ return next;
3784
+ });
3785
+ }, !0), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3763
3786
  var force = forced || (shouldUpdate == null ? void 0 : shouldUpdate()) || props.deopt || props["disable-child-theme"], shouldTryUpdate = force ?? !!(keys != null && keys.length || isNewTheme);
3764
3787
  process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", themeManager.id, {
3765
3788
  force,
@@ -3768,9 +3791,9 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3768
3791
  name,
3769
3792
  manager,
3770
3793
  keys
3771
- }), shouldTryUpdate && (console.error = preventWarnSetState, setThemeState(function(prev) {
3794
+ }), shouldTryUpdate && setThemeState(function(prev) {
3772
3795
  return createState(prev, force);
3773
- }), console.error = ogLog);
3796
+ });
3774
3797
  }, themeManager.id);
3775
3798
  return function() {
3776
3799
  selfListenerDispose(), disposeChangeListener == null || disposeChangeListener(), isNewTheme && activeThemeManagers.delete(themeManager);
@@ -3837,7 +3860,7 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3837
3860
  (0, import_createShallowSetState.isEqualShallow)(prev, response) && // ... and then compare just the state, because we make a new state obj but is likely the same
3838
3861
  (0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
3839
3862
  if (prev && shouldReturnPrev) return prev;
3840
- if (response.state = state2, process.env.NODE_ENV === "development" && props.debug && import_constants2.isClient) {
3863
+ if (response.state = state2, response.prevState = prev == null ? void 0 : prev.state, process.env.NODE_ENV === "development" && props.debug && import_constants2.isClient) {
3841
3864
  console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
3842
3865
  var parentState = {
3843
3866
  ...parentManager == null ? void 0 : parentManager.state