@tamagui/core 1.0.1-beta.183 → 1.0.1-beta.185

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.1-beta.183",
3
+ "version": "1.0.1-beta.185",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -28,14 +28,14 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@expo/match-media": "^0.3.0",
31
- "@tamagui/compose-refs": "^1.0.1-beta.183",
32
- "@tamagui/helpers": "^1.0.1-beta.183",
33
- "@tamagui/normalize-css-color-lite": "^1.0.1-beta.183",
34
- "@tamagui/rnw": "^1.0.1-beta.183",
35
- "@tamagui/rnw-lite": "^1.0.1-beta.183",
36
- "@tamagui/use-debounce": "^1.0.1-beta.183",
37
- "@tamagui/use-event": "^1.0.1-beta.183",
38
- "@tamagui/use-force-update": "^1.0.1-beta.183",
31
+ "@tamagui/compose-refs": "^1.0.1-beta.185",
32
+ "@tamagui/helpers": "^1.0.1-beta.185",
33
+ "@tamagui/normalize-css-color-lite": "^1.0.1-beta.185",
34
+ "@tamagui/rnw": "^1.0.1-beta.185",
35
+ "@tamagui/rnw-lite": "^1.0.1-beta.185",
36
+ "@tamagui/use-debounce": "^1.0.1-beta.185",
37
+ "@tamagui/use-event": "^1.0.1-beta.185",
38
+ "@tamagui/use-force-update": "^1.0.1-beta.185",
39
39
  "expo-screen-orientation": "^4.3.0",
40
40
  "hyphenate-style-name": "^1.0.4"
41
41
  },
@@ -44,7 +44,7 @@
44
44
  "react-dom": "*"
45
45
  },
46
46
  "devDependencies": {
47
- "@tamagui/build": "^1.0.1-beta.183",
47
+ "@tamagui/build": "^1.0.1-beta.185",
48
48
  "@types/node": "^16.11.9",
49
49
  "@types/react": "^18.0.15",
50
50
  "csstype": "^3.0.10",
@@ -23,3 +23,19 @@ export const useIsomorphicLayoutEffect = isRSC ? idFn : isServer ? useEffect : u
23
23
  export const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent || '')
24
24
  export const isWebTouchable = isClient && 'ontouchstart' in window
25
25
  export const isTouchable = !isWeb || isWebTouchable
26
+
27
+ if (process.env.NODE_ENV === 'development') {
28
+ if (!process.env.TAMAGUI_TARGET) {
29
+ // eslint-disable-next-line no-console
30
+ console.warn(`Must set TAMAGUI_TARGET to "web" or "native"`)
31
+ } else if (
32
+ isClient &&
33
+ process.env.TAMAGUI_TARGET !== 'web' &&
34
+ process.env.TAMAGUI_IGNORE_TARGET !== '1'
35
+ ) {
36
+ // eslint-disable-next-line no-console
37
+ console.warn(
38
+ `Must set TAMAGUI_TARGET to "web" for web apps - if you have window defined outside of the browser, set TAMAGUI_IGNORE_TARGET=1 to hide this`
39
+ )
40
+ }
41
+ }
@@ -42,11 +42,7 @@ import { getAllSelectors } from './helpers/insertStyleRule'
42
42
  import { mergeProps } from './helpers/mergeProps'
43
43
  import { proxyThemeVariables } from './helpers/proxyThemeVariables'
44
44
  import { useShallowSetState } from './helpers/useShallowSetState'
45
- import {
46
- addMediaQueryListener,
47
- getInitialMediaState,
48
- removeMediaQueryListener,
49
- } from './hooks/useMedia'
45
+ import { addMediaQueryListener, getCurrentMediaState } from './hooks/useMedia'
50
46
  import { usePressable } from './hooks/usePressable'
51
47
  import { useServerRef, useServerState } from './hooks/useServerHooks'
52
48
  import { getThemeManager, useTheme } from './hooks/useTheme'
@@ -1103,7 +1099,7 @@ export function createComponent<
1103
1099
  // only used by enterStyle
1104
1100
  mounted: false,
1105
1101
  animation: null,
1106
- mediaState: getInitialMediaState(),
1102
+ mediaState: getCurrentMediaState(),
1107
1103
  })
1108
1104
  }
1109
1105
 
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useState } from 'react'
1
+ import { startTransition, useEffect, useMemo, useState } from 'react'
2
2
 
3
3
  import { useIsomorphicLayoutEffect } from '../constants/platform'
4
4
  import { matchMedia } from '../helpers/matchMedia'
@@ -53,9 +53,6 @@ export const getMedia = () => {
53
53
 
54
54
  const dispose = new Set<Function>()
55
55
 
56
- // for SSR capture it at time of startup
57
- let initialMediaState: MediaQueryState | null
58
-
59
56
  export const configureMedia = (config: TamaguiInternalConfig) => {
60
57
  const { media, mediaQueryDefaultActive } = config
61
58
  if (!media) return
@@ -63,13 +60,15 @@ export const configureMedia = (config: TamaguiInternalConfig) => {
63
60
  mediaState[key] = mediaQueryDefaultActive?.[key] || false
64
61
  }
65
62
  Object.assign(mediaQueryConfig, media)
66
- initialMediaState = { ...mediaState }
63
+ currentMediaState = { ...mediaState }
67
64
  if (config.disableSSR) {
68
65
  setupMediaListeners()
69
66
  }
70
67
  }
71
68
 
72
- export const getInitialMediaState = () => initialMediaState
69
+ // for SSR capture it at time of startup
70
+ let currentMediaState: MediaQueryState | null
71
+ export const getCurrentMediaState = () => currentMediaState
73
72
 
74
73
  function unlisten() {
75
74
  dispose.forEach((cb) => cb())
@@ -93,29 +92,34 @@ function setupMediaListeners() {
93
92
  // hmr, undo existing before re-binding
94
93
  unlisten()
95
94
 
96
- for (const key in mediaQueryConfig) {
97
- const str = mediaObjectToString(mediaQueryConfig[key])
98
- const getMatch = () => matchMedia(str)
99
- const match = getMatch()
100
- if (!match) {
101
- throw new Error('⚠️ No match')
102
- }
103
- // react native needs these deprecated apis for now
104
- match.addListener(update)
105
- dispose.add(() => match.removeListener(update))
106
-
107
- update()
108
-
109
- function update() {
110
- const next = !!getMatch().matches
111
- if (next === mediaState[key]) return
112
- mediaState[key] = next
113
- const listeners = mediaQueryListeners[key]
114
- if (listeners?.size) {
115
- listeners.forEach((cb) => cb(next))
95
+ // theoretically this should make media reactions smoother but potentially delayed?
96
+ // but i believe consistent, so that's a nicer default (we'll see)
97
+ startTransition(() => {
98
+ for (const key in mediaQueryConfig) {
99
+ const str = mediaObjectToString(mediaQueryConfig[key])
100
+ const getMatch = () => matchMedia(str)
101
+ const match = getMatch()
102
+ if (!match) {
103
+ throw new Error('⚠️ No match')
104
+ }
105
+ // react native needs these deprecated apis for now
106
+ match.addListener(update)
107
+ dispose.add(() => match.removeListener(update))
108
+
109
+ update()
110
+
111
+ function update() {
112
+ const next = !!getMatch().matches
113
+ if (next === mediaState[key]) return
114
+ mediaState[key] = next
115
+ currentMediaState = { ...mediaState }
116
+ const listeners = mediaQueryListeners[key]
117
+ if (listeners?.size) {
118
+ listeners.forEach((cb) => cb(next))
119
+ }
116
120
  }
117
121
  }
118
- }
122
+ })
119
123
  }
120
124
 
121
125
  export function useMediaQueryListeners(config: TamaguiInternalConfig) {
@@ -132,7 +136,7 @@ export function useMediaQueryListeners(config: TamaguiInternalConfig) {
132
136
  export function useMedia(): {
133
137
  [key in MediaQueryKey]: boolean
134
138
  } {
135
- const [state, setState] = useState(initialMediaState || {})
139
+ const [state, setState] = useState(currentMediaState || {})
136
140
  const keys = useSafeRef({} as Record<string, boolean>)
137
141
 
138
142
  function updateState() {
@@ -161,7 +165,7 @@ export function useMedia(): {
161
165
  new Proxy(state, {
162
166
  get(_, key: string) {
163
167
  if (process.env.NODE_ENV === 'development') {
164
- if (!initialMediaState) {
168
+ if (!currentMediaState) {
165
169
  throw new Error(
166
170
  `To use useMedia() you must pass in media configuration to createTamagui, none was found.`
167
171
  )
@@ -6,7 +6,7 @@ export declare function removeMediaQueryListener(key: MediaQueryKey, cb: MediaLi
6
6
  export declare const mediaQueryConfig: MediaQueries;
7
7
  export declare const getMedia: () => MediaQueryState;
8
8
  export declare const configureMedia: (config: TamaguiInternalConfig) => void;
9
- export declare const getInitialMediaState: () => MediaQueryState | null;
9
+ export declare const getCurrentMediaState: () => MediaQueryState | null;
10
10
  export declare function useMediaQueryListeners(config: TamaguiInternalConfig): void;
11
11
  export declare function useMedia(): {
12
12
  [key in MediaQueryKey]: boolean;