@tamagui/core 1.0.1-beta.188 → 1.0.1-beta.189
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/cjs/createComponent.js +1 -1
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +6 -11
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/createComponent.js +2 -2
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +5 -10
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +2 -2
- package/package.json +11 -11
- package/src/createComponent.tsx +3 -2
- package/src/hooks/useMedia.tsx +5 -15
- package/src/index.ts +3 -2
- package/types/hooks/useMedia.d.ts +1 -1
- package/types/index.d.ts +3 -2
- package/src/hooks/useIsSSR.tsx +0 -25
package/src/hooks/useMedia.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
2
|
import { startTransition, useEffect, useMemo, useState } from 'react'
|
|
3
3
|
|
|
4
|
+
import { getConfig } from '../config'
|
|
4
5
|
import { matchMedia } from '../helpers/matchMedia'
|
|
5
6
|
import {
|
|
6
7
|
MediaQueries,
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
TamaguiInternalConfig,
|
|
11
12
|
} from '../types'
|
|
12
13
|
import { useSafeRef } from './useSafeRef'
|
|
13
|
-
import { getConfig } from '..'
|
|
14
14
|
|
|
15
15
|
export const mediaState: MediaQueryState =
|
|
16
16
|
// development time safeguard
|
|
@@ -55,10 +55,9 @@ export const getMedia = () => {
|
|
|
55
55
|
// for SSR capture it at time of startup
|
|
56
56
|
let currentMediaState: MediaQueryState | null
|
|
57
57
|
let initialMediaState: MediaQueryState | null
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (getConfig().disableSSR || hasFinishedInitialRender) {
|
|
58
|
+
|
|
59
|
+
export const getInitialMediaState = () => {
|
|
60
|
+
if (getConfig().disableSSR) {
|
|
62
61
|
return currentMediaState || {}
|
|
63
62
|
}
|
|
64
63
|
return initialMediaState || {}
|
|
@@ -132,21 +131,12 @@ function setupMediaListeners() {
|
|
|
132
131
|
})
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
const onIdle =
|
|
136
|
-
typeof requestIdleCallback === 'undefined' ? (cb) => setTimeout(cb, 100) : requestIdleCallback
|
|
137
|
-
|
|
138
134
|
export function useMediaQueryListeners(config: TamaguiInternalConfig) {
|
|
139
135
|
if (config.disableSSR) {
|
|
140
136
|
return
|
|
141
137
|
}
|
|
142
|
-
|
|
143
138
|
useEffect(() => {
|
|
144
139
|
setupMediaListeners()
|
|
145
|
-
|
|
146
|
-
onIdle(() => {
|
|
147
|
-
hasFinishedInitialRender = true
|
|
148
|
-
})
|
|
149
|
-
|
|
150
140
|
return unlisten
|
|
151
141
|
}, [])
|
|
152
142
|
}
|
|
@@ -154,7 +144,7 @@ export function useMediaQueryListeners(config: TamaguiInternalConfig) {
|
|
|
154
144
|
export function useMedia(): {
|
|
155
145
|
[key in MediaQueryKey]: boolean
|
|
156
146
|
} {
|
|
157
|
-
const [state, setState] = useState(
|
|
147
|
+
const [state, setState] = useState<MediaQueryState>(initialMediaState || {})
|
|
158
148
|
const keys = useSafeRef({} as Record<string, boolean>)
|
|
159
149
|
|
|
160
150
|
function updateState() {
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,6 @@ export type { RNWTextProps, RNWViewProps } from './types-rnw'
|
|
|
18
18
|
export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './config'
|
|
19
19
|
|
|
20
20
|
export * from './constants/constants'
|
|
21
|
-
export * from '@tamagui/constants'
|
|
22
21
|
export { createDOMProps } from '@tamagui/rnw'
|
|
23
22
|
|
|
24
23
|
export * from './helpers/calc'
|
|
@@ -62,7 +61,6 @@ export {
|
|
|
62
61
|
} from './hooks/useMedia'
|
|
63
62
|
export * from './hooks/usePressable'
|
|
64
63
|
export * from './hooks/useTheme'
|
|
65
|
-
export * from './hooks/useIsSSR'
|
|
66
64
|
export * from './hooks/useUnmountEffect'
|
|
67
65
|
export * from './hooks/useSafeRef'
|
|
68
66
|
|
|
@@ -78,5 +76,8 @@ export * from './views/FontLanguage'
|
|
|
78
76
|
export * from './views/TamaguiProvider'
|
|
79
77
|
|
|
80
78
|
export * from '@tamagui/use-force-update'
|
|
79
|
+
export * from '@tamagui/use-did-finish-ssr'
|
|
81
80
|
export * from '@tamagui/use-event'
|
|
81
|
+
export * from '@tamagui/compose-refs'
|
|
82
82
|
export * from '@tamagui/helpers'
|
|
83
|
+
export * from '@tamagui/constants'
|
|
@@ -5,7 +5,7 @@ export declare function addMediaQueryListener(key: MediaQueryKey, cb: MediaListe
|
|
|
5
5
|
export declare function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener): void;
|
|
6
6
|
export declare const mediaQueryConfig: MediaQueries;
|
|
7
7
|
export declare const getMedia: () => MediaQueryState;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const getInitialMediaState: () => MediaQueryState;
|
|
9
9
|
export declare const configureMedia: (config: TamaguiInternalConfig) => void;
|
|
10
10
|
export declare function useMediaQueryListeners(config: TamaguiInternalConfig): void;
|
|
11
11
|
export declare function useMedia(): {
|
package/types/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export * from './types';
|
|
|
15
15
|
export type { RNWTextProps, RNWViewProps } from './types-rnw';
|
|
16
16
|
export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './config';
|
|
17
17
|
export * from './constants/constants';
|
|
18
|
-
export * from '@tamagui/constants';
|
|
19
18
|
export { createDOMProps } from '@tamagui/rnw';
|
|
20
19
|
export * from './helpers/calc';
|
|
21
20
|
export * from './helpers/useShallowSetState';
|
|
@@ -45,7 +44,6 @@ export * from './hooks/useIsTouchDevice';
|
|
|
45
44
|
export { configureMedia, getMedia, mediaState, useMedia, useMediaPropsActive, mediaObjectToString, addMediaQueryListener, removeMediaQueryListener, mediaQueryConfig, } from './hooks/useMedia';
|
|
46
45
|
export * from './hooks/usePressable';
|
|
47
46
|
export * from './hooks/useTheme';
|
|
48
|
-
export * from './hooks/useIsSSR';
|
|
49
47
|
export * from './hooks/useUnmountEffect';
|
|
50
48
|
export * from './hooks/useSafeRef';
|
|
51
49
|
export * from './views/Slot';
|
|
@@ -59,6 +57,9 @@ export * from './views/ThemeReset';
|
|
|
59
57
|
export * from './views/FontLanguage';
|
|
60
58
|
export * from './views/TamaguiProvider';
|
|
61
59
|
export * from '@tamagui/use-force-update';
|
|
60
|
+
export * from '@tamagui/use-did-finish-ssr';
|
|
62
61
|
export * from '@tamagui/use-event';
|
|
62
|
+
export * from '@tamagui/compose-refs';
|
|
63
63
|
export * from '@tamagui/helpers';
|
|
64
|
+
export * from '@tamagui/constants';
|
|
64
65
|
//# sourceMappingURL=index.d.ts.map
|
package/src/hooks/useIsSSR.tsx
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isServer, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
|
|
4
|
-
import { startTransition } from '../helpers/startTransition'
|
|
5
|
-
|
|
6
|
-
// because any change before first useEffect causes hydration / mismatch issues
|
|
7
|
-
|
|
8
|
-
export const useIsSSR = (props?: { immediate?: boolean }) => {
|
|
9
|
-
const [val, setVal] = useState(true)
|
|
10
|
-
|
|
11
|
-
if (isWeb && !isServer) {
|
|
12
|
-
useIsomorphicLayoutEffect(() => {
|
|
13
|
-
// could also have a global tamagui `config.immediateSSRTransition`
|
|
14
|
-
if (props?.immediate) {
|
|
15
|
-
setVal(false)
|
|
16
|
-
} else {
|
|
17
|
-
startTransition(() => {
|
|
18
|
-
setVal(false)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
}, [])
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return val
|
|
25
|
-
}
|