@tamagui/native 2.0.0-1769256574467
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/components.cjs +66 -0
- package/dist/cjs/components.js +41 -0
- package/dist/cjs/components.js.map +6 -0
- package/dist/cjs/components.native.js +75 -0
- package/dist/cjs/components.native.js.map +1 -0
- package/dist/cjs/gestureState.cjs +47 -0
- package/dist/cjs/gestureState.js +42 -0
- package/dist/cjs/gestureState.js.map +6 -0
- package/dist/cjs/gestureState.native.js +50 -0
- package/dist/cjs/gestureState.native.js.map +1 -0
- package/dist/cjs/index.cjs +38 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js +41 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/portalState.cjs +36 -0
- package/dist/cjs/portalState.js +28 -0
- package/dist/cjs/portalState.js.map +6 -0
- package/dist/cjs/portalState.native.js +39 -0
- package/dist/cjs/portalState.native.js.map +1 -0
- package/dist/cjs/setup-gesture-handler.cjs +27 -0
- package/dist/cjs/setup-gesture-handler.js +24 -0
- package/dist/cjs/setup-gesture-handler.js.map +6 -0
- package/dist/cjs/setup-gesture-handler.native.js +30 -0
- package/dist/cjs/setup-gesture-handler.native.js.map +1 -0
- package/dist/cjs/setup-portal.cjs +66 -0
- package/dist/cjs/setup-portal.js +53 -0
- package/dist/cjs/setup-portal.js.map +6 -0
- package/dist/cjs/setup-portal.native.js +74 -0
- package/dist/cjs/setup-portal.native.js.map +1 -0
- package/dist/cjs/setup-worklets.cjs +18 -0
- package/dist/cjs/setup-worklets.js +20 -0
- package/dist/cjs/setup-worklets.js.map +6 -0
- package/dist/cjs/setup-worklets.native.js +21 -0
- package/dist/cjs/setup-worklets.native.js.map +1 -0
- package/dist/cjs/setup.cjs +64 -0
- package/dist/cjs/setup.js +50 -0
- package/dist/cjs/setup.js.map +6 -0
- package/dist/cjs/setup.native.js +72 -0
- package/dist/cjs/setup.native.js.map +1 -0
- package/dist/cjs/state.cjs +36 -0
- package/dist/cjs/state.js +28 -0
- package/dist/cjs/state.js.map +6 -0
- package/dist/cjs/state.native.js +39 -0
- package/dist/cjs/state.native.js.map +1 -0
- package/dist/cjs/workletsState.cjs +48 -0
- package/dist/cjs/workletsState.js +43 -0
- package/dist/cjs/workletsState.js.map +6 -0
- package/dist/cjs/workletsState.native.js +51 -0
- package/dist/cjs/workletsState.native.js.map +1 -0
- package/dist/esm/components.js +26 -0
- package/dist/esm/components.js.map +6 -0
- package/dist/esm/components.mjs +41 -0
- package/dist/esm/components.mjs.map +1 -0
- package/dist/esm/components.native.js +47 -0
- package/dist/esm/components.native.js.map +1 -0
- package/dist/esm/gestureState.js +26 -0
- package/dist/esm/gestureState.js.map +6 -0
- package/dist/esm/gestureState.mjs +22 -0
- package/dist/esm/gestureState.mjs.map +1 -0
- package/dist/esm/gestureState.native.js +22 -0
- package/dist/esm/gestureState.native.js.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +6 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/portalState.js +12 -0
- package/dist/esm/portalState.js.map +6 -0
- package/dist/esm/portalState.mjs +12 -0
- package/dist/esm/portalState.mjs.map +1 -0
- package/dist/esm/portalState.native.js +12 -0
- package/dist/esm/portalState.native.js.map +1 -0
- package/dist/esm/setup-gesture-handler.js +24 -0
- package/dist/esm/setup-gesture-handler.js.map +6 -0
- package/dist/esm/setup-gesture-handler.mjs +28 -0
- package/dist/esm/setup-gesture-handler.mjs.map +1 -0
- package/dist/esm/setup-gesture-handler.native.js +28 -0
- package/dist/esm/setup-gesture-handler.native.js.map +1 -0
- package/dist/esm/setup-portal.js +37 -0
- package/dist/esm/setup-portal.js.map +6 -0
- package/dist/esm/setup-portal.mjs +43 -0
- package/dist/esm/setup-portal.mjs.map +1 -0
- package/dist/esm/setup-portal.native.js +48 -0
- package/dist/esm/setup-portal.native.js.map +1 -0
- package/dist/esm/setup-worklets.js +20 -0
- package/dist/esm/setup-worklets.js.map +6 -0
- package/dist/esm/setup-worklets.mjs +19 -0
- package/dist/esm/setup-worklets.mjs.map +1 -0
- package/dist/esm/setup-worklets.native.js +19 -0
- package/dist/esm/setup-worklets.native.js.map +1 -0
- package/dist/esm/setup.js +34 -0
- package/dist/esm/setup.js.map +6 -0
- package/dist/esm/setup.mjs +41 -0
- package/dist/esm/setup.mjs.map +1 -0
- package/dist/esm/setup.native.js +46 -0
- package/dist/esm/setup.native.js.map +1 -0
- package/dist/esm/state.js +12 -0
- package/dist/esm/state.js.map +6 -0
- package/dist/esm/state.mjs +12 -0
- package/dist/esm/state.mjs.map +1 -0
- package/dist/esm/state.native.js +12 -0
- package/dist/esm/state.native.js.map +1 -0
- package/dist/esm/workletsState.js +27 -0
- package/dist/esm/workletsState.js.map +6 -0
- package/dist/esm/workletsState.mjs +23 -0
- package/dist/esm/workletsState.mjs.map +1 -0
- package/dist/esm/workletsState.native.js +23 -0
- package/dist/esm/workletsState.native.js.map +1 -0
- package/package.json +110 -0
- package/src/components.tsx +55 -0
- package/src/gestureState.ts +34 -0
- package/src/index.ts +39 -0
- package/src/portalState.ts +15 -0
- package/src/setup-gesture-handler.ts +51 -0
- package/src/setup-portal.ts +63 -0
- package/src/setup-worklets.ts +49 -0
- package/src/workletsState.ts +36 -0
- package/types/components.d.ts +28 -0
- package/types/components.d.ts.map +11 -0
- package/types/gestureState.d.ts +11 -0
- package/types/gestureState.d.ts.map +11 -0
- package/types/index.d.ts +26 -0
- package/types/index.d.ts.map +11 -0
- package/types/portalState.d.ts +8 -0
- package/types/portalState.d.ts.map +11 -0
- package/types/setup-gesture-handler.d.ts +3 -0
- package/types/setup-gesture-handler.d.ts.map +11 -0
- package/types/setup-portal.d.ts +3 -0
- package/types/setup-portal.d.ts.map +11 -0
- package/types/setup-worklets.d.ts +3 -0
- package/types/setup-worklets.d.ts.map +11 -0
- package/types/workletsState.d.ts +12 -0
- package/types/workletsState.d.ts.map +11 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const GLOBAL_KEY = '__tamagui_native_gesture_state__'
|
|
2
|
+
|
|
3
|
+
export interface GestureState {
|
|
4
|
+
enabled: boolean
|
|
5
|
+
Gesture: any
|
|
6
|
+
GestureDetector: any
|
|
7
|
+
ScrollView: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getGlobalState(): GestureState {
|
|
11
|
+
const g = globalThis as any
|
|
12
|
+
if (!g[GLOBAL_KEY]) {
|
|
13
|
+
g[GLOBAL_KEY] = {
|
|
14
|
+
enabled: false,
|
|
15
|
+
Gesture: null,
|
|
16
|
+
GestureDetector: null,
|
|
17
|
+
ScrollView: null,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return g[GLOBAL_KEY]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isGestureHandlerEnabled(): boolean {
|
|
24
|
+
return getGlobalState().enabled
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getGestureHandlerState(): GestureState {
|
|
28
|
+
return getGlobalState()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function setGestureHandlerState(updates: Partial<GestureState>): void {
|
|
32
|
+
const state = getGlobalState()
|
|
33
|
+
Object.assign(state, updates)
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamagui/native
|
|
3
|
+
*
|
|
4
|
+
* Native setup modules for Tamagui. Import these at the top of your app entry point.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* // In your app entry (index.js or App.tsx)
|
|
9
|
+
* import '@tamagui/native/setup-portal'
|
|
10
|
+
* import '@tamagui/native/setup-gesture-handler'
|
|
11
|
+
* import '@tamagui/native/setup-worklets'
|
|
12
|
+
*
|
|
13
|
+
* // Then use Tamagui components normally
|
|
14
|
+
* // Sheet will automatically use native gestures when available
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// portal state exports (safe - no side effects)
|
|
19
|
+
export { getNativePortalState, setNativePortalState } from './portalState'
|
|
20
|
+
export type { NativePortalState } from './portalState'
|
|
21
|
+
|
|
22
|
+
export { NativePortal, NativePortalHost, NativePortalProvider } from './components'
|
|
23
|
+
export type {
|
|
24
|
+
NativePortalProps,
|
|
25
|
+
NativePortalHostProps,
|
|
26
|
+
NativePortalProviderProps,
|
|
27
|
+
} from './components'
|
|
28
|
+
|
|
29
|
+
// gesture handler state exports (safe - no side effects)
|
|
30
|
+
export {
|
|
31
|
+
isGestureHandlerEnabled,
|
|
32
|
+
getGestureHandlerState,
|
|
33
|
+
setGestureHandlerState,
|
|
34
|
+
} from './gestureState'
|
|
35
|
+
export type { GestureState } from './gestureState'
|
|
36
|
+
|
|
37
|
+
// worklets state exports (safe - no side effects)
|
|
38
|
+
export { isWorkletsEnabled, getWorkletsState } from './workletsState'
|
|
39
|
+
export type { WorkletsState } from './workletsState'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type NativePortalState = {
|
|
2
|
+
enabled: boolean
|
|
3
|
+
type: 'teleport' | 'legacy' | null
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let state: NativePortalState = { enabled: false, type: null }
|
|
7
|
+
|
|
8
|
+
export function setNativePortalState(newState: NativePortalState) {
|
|
9
|
+
state = newState
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getNativePortalState(): NativePortalState {
|
|
13
|
+
return state
|
|
14
|
+
}
|
|
15
|
+
// retrigger ci
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup gesture handler for Tamagui native components.
|
|
3
|
+
*
|
|
4
|
+
* Simply import this module at the top of your app entry point:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import '@tamagui/native/setup-gesture-handler'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This automatically detects and configures react-native-gesture-handler
|
|
12
|
+
* for use with Sheet and other gesture-aware components.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { setGestureHandlerState } from './gestureState'
|
|
16
|
+
|
|
17
|
+
function setup() {
|
|
18
|
+
const g = globalThis as any
|
|
19
|
+
if (g.__tamagui_native_gesture_setup_complete) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
g.__tamagui_native_gesture_setup_complete = true
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// dynamically require RNGH - it should already be imported by the app
|
|
26
|
+
const rngh = require('react-native-gesture-handler')
|
|
27
|
+
const { Gesture, GestureDetector, ScrollView } = rngh
|
|
28
|
+
|
|
29
|
+
if (Gesture && GestureDetector) {
|
|
30
|
+
setGestureHandlerState({
|
|
31
|
+
enabled: true,
|
|
32
|
+
Gesture,
|
|
33
|
+
GestureDetector,
|
|
34
|
+
ScrollView: ScrollView || null,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// also set on the legacy key for backward compat with @tamagui/sheet
|
|
38
|
+
g.__tamagui_sheet_gesture_state__ = {
|
|
39
|
+
enabled: true,
|
|
40
|
+
Gesture,
|
|
41
|
+
GestureDetector,
|
|
42
|
+
ScrollView: ScrollView || null,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
// RNGH not available, that's fine
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// run setup immediately on import
|
|
51
|
+
setup()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup native portal support for Tamagui.
|
|
3
|
+
*
|
|
4
|
+
* Simply import this module at the top of your app entry point:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import '@tamagui/native/setup-portal'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This automatically detects and configures react-native-teleport for portals.
|
|
12
|
+
* Falls back to legacy RN shims if teleport is not installed.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { setNativePortalState } from './portalState'
|
|
16
|
+
|
|
17
|
+
const IS_FABRIC =
|
|
18
|
+
typeof global !== 'undefined' &&
|
|
19
|
+
Boolean((global as any)._IS_FABRIC ?? (global as any).nativeFabricUIManager)
|
|
20
|
+
|
|
21
|
+
function setup() {
|
|
22
|
+
const g = globalThis as any
|
|
23
|
+
if (g.__tamagui_native_portal_setup) return
|
|
24
|
+
g.__tamagui_native_portal_setup = true
|
|
25
|
+
|
|
26
|
+
// try teleport first (preferred)
|
|
27
|
+
try {
|
|
28
|
+
const teleport = require('react-native-teleport')
|
|
29
|
+
if (teleport?.Portal && teleport?.PortalHost && teleport?.PortalProvider) {
|
|
30
|
+
g.__tamagui_teleport = teleport
|
|
31
|
+
setNativePortalState({ enabled: true, type: 'teleport' })
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
// teleport not installed, try legacy
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// fall back to legacy RN shims approach
|
|
39
|
+
if (IS_FABRIC) {
|
|
40
|
+
try {
|
|
41
|
+
const mod = require('react-native/Libraries/Renderer/shims/ReactFabric')
|
|
42
|
+
g.__tamagui_portal_create = mod?.default?.createPortal ?? mod.createPortal
|
|
43
|
+
setNativePortalState({ enabled: true, type: 'legacy' })
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.info(`Note: error importing fabric portal, native portals disabled`, err)
|
|
46
|
+
}
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const mod = require('react-native/Libraries/Renderer/shims/ReactNative')
|
|
52
|
+
g.__tamagui_portal_create = mod?.default?.createPortal ?? mod.createPortal
|
|
53
|
+
setNativePortalState({ enabled: true, type: 'legacy' })
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.info(`Note: error importing native portal, native portals disabled`, err)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// run setup immediately on import
|
|
60
|
+
setup()
|
|
61
|
+
|
|
62
|
+
// keep the function export for backward compatibility
|
|
63
|
+
export const setupNativePortal = setup
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup worklets for Tamagui native components.
|
|
3
|
+
*
|
|
4
|
+
* Simply import this module at the top of your app entry point:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import '@tamagui/native/setup-worklets'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This automatically detects and configures react-native-worklets-core
|
|
12
|
+
* for use with Sheet and other components that benefit from synchronous
|
|
13
|
+
* native-thread execution.
|
|
14
|
+
*
|
|
15
|
+
* When combined with setup-gesture-handler, Sheet gets native-quality
|
|
16
|
+
* gesture coordination between sheet dragging and scroll views.
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { setWorkletsState } from './workletsState'
|
|
22
|
+
|
|
23
|
+
function setup() {
|
|
24
|
+
const g = globalThis as any
|
|
25
|
+
if (g.__tamagui_native_worklets_setup_complete) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
g.__tamagui_native_worklets_setup_complete = true
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
// dynamically require worklets-core
|
|
32
|
+
const worklets = require('react-native-worklets-core')
|
|
33
|
+
|
|
34
|
+
if (worklets) {
|
|
35
|
+
setWorkletsState({
|
|
36
|
+
enabled: true,
|
|
37
|
+
Worklets: worklets.Worklets,
|
|
38
|
+
useRunOnJS: worklets.useRunOnJS,
|
|
39
|
+
useWorklet: worklets.useWorklet,
|
|
40
|
+
createWorkletContextValue: worklets.createWorkletContextValue,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
// worklets not available, that's fine - will fall back to JS thread
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// run setup immediately on import
|
|
49
|
+
setup()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const GLOBAL_KEY = '__tamagui_native_worklets_state__'
|
|
2
|
+
|
|
3
|
+
export interface WorkletsState {
|
|
4
|
+
enabled: boolean
|
|
5
|
+
Worklets: any
|
|
6
|
+
useRunOnJS: any
|
|
7
|
+
useWorklet: any
|
|
8
|
+
createWorkletContextValue: any
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getGlobalState(): WorkletsState {
|
|
12
|
+
const g = globalThis as any
|
|
13
|
+
if (!g[GLOBAL_KEY]) {
|
|
14
|
+
g[GLOBAL_KEY] = {
|
|
15
|
+
enabled: false,
|
|
16
|
+
Worklets: null,
|
|
17
|
+
useRunOnJS: null,
|
|
18
|
+
useWorklet: null,
|
|
19
|
+
createWorkletContextValue: null,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return g[GLOBAL_KEY]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isWorkletsEnabled(): boolean {
|
|
26
|
+
return getGlobalState().enabled
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getWorkletsState(): WorkletsState {
|
|
30
|
+
return getGlobalState()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function setWorkletsState(updates: Partial<WorkletsState>): void {
|
|
34
|
+
const state = getGlobalState()
|
|
35
|
+
Object.assign(state, updates)
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type NativePortalProps = {
|
|
3
|
+
hostName?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export type NativePortalHostProps = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export type NativePortalProviderProps = {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Renders children into a teleport Portal when available.
|
|
14
|
+
* Returns null when teleport is not set up (allows fallback handling by caller).
|
|
15
|
+
*/
|
|
16
|
+
export declare function NativePortal({ hostName, children }: NativePortalProps): ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Renders a teleport PortalHost when available.
|
|
19
|
+
* Returns null when teleport is not set up.
|
|
20
|
+
*/
|
|
21
|
+
export declare function NativePortalHost({ name }: NativePortalHostProps): ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Wraps children with teleport PortalProvider when available.
|
|
24
|
+
* Returns children as-is when teleport is not set up.
|
|
25
|
+
*/
|
|
26
|
+
export declare function NativePortalProvider({ children }: NativePortalProviderProps): ReactNode;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,iBAAiB;AAI/B,YAAY,oBAAoB;CAC9B;CACA,UAAU;;AAGZ,YAAY,wBAAwB;CAClC;;AAGF,YAAY,4BAA4B;CACtC,UAAU;;;;;;AAOZ,OAAO,iBAAS,aAAa,EAC3B,UACA,YACC,oBAAoB;;;;;AAYvB,OAAO,iBAAS,iBAAiB,EAAE,QAAQ,wBAAwB;;;;;AAYnE,OAAO,iBAAS,qBAAqB,EAAE,YAAY,4BAA4B",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/components.tsx"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"import type { ReactNode } from 'react'\nimport { getNativePortalState } from './portalState'\n\n// types matching react-native-teleport's API\nexport type NativePortalProps = {\n hostName?: string\n children: ReactNode\n}\n\nexport type NativePortalHostProps = {\n name: string\n}\n\nexport type NativePortalProviderProps = {\n children: ReactNode\n}\n\n/**\n * Renders children into a teleport Portal when available.\n * Returns null when teleport is not set up (allows fallback handling by caller).\n */\nexport function NativePortal({\n hostName = 'root',\n children,\n}: NativePortalProps): ReactNode {\n const state = getNativePortalState()\n if (state.type !== 'teleport') return null\n\n const { Portal } = (globalThis as any).__tamagui_teleport\n return <Portal hostName={hostName}>{children}</Portal>\n}\n\n/**\n * Renders a teleport PortalHost when available.\n * Returns null when teleport is not set up.\n */\nexport function NativePortalHost({ name }: NativePortalHostProps): ReactNode {\n const state = getNativePortalState()\n if (state.type !== 'teleport') return null\n\n const { PortalHost } = (globalThis as any).__tamagui_teleport\n return <PortalHost name={name} />\n}\n\n/**\n * Wraps children with teleport PortalProvider when available.\n * Returns children as-is when teleport is not set up.\n */\nexport function NativePortalProvider({ children }: NativePortalProviderProps): ReactNode {\n const state = getNativePortalState()\n if (state.type !== 'teleport') return <>{children}</>\n\n const { PortalProvider } = (globalThis as any).__tamagui_teleport\n return <PortalProvider>{children}</PortalProvider>\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface GestureState {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
Gesture: any;
|
|
4
|
+
GestureDetector: any;
|
|
5
|
+
ScrollView: any;
|
|
6
|
+
}
|
|
7
|
+
export declare function isGestureHandlerEnabled(): boolean;
|
|
8
|
+
export declare function getGestureHandlerState(): GestureState;
|
|
9
|
+
export declare function setGestureHandlerState(updates: Partial<GestureState>): void;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=gestureState.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAEA,iBAAiB,aAAa;CAC5B;CACA;CACA;CACA;;AAgBF,OAAO,iBAAS;AAIhB,OAAO,iBAAS,0BAA0B;AAI1C,OAAO,iBAAS,uBAAuB,SAAS,QAAQ",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/gestureState.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"const GLOBAL_KEY = '__tamagui_native_gesture_state__'\n\nexport interface GestureState {\n enabled: boolean\n Gesture: any\n GestureDetector: any\n ScrollView: any\n}\n\nfunction getGlobalState(): GestureState {\n const g = globalThis as any\n if (!g[GLOBAL_KEY]) {\n g[GLOBAL_KEY] = {\n enabled: false,\n Gesture: null,\n GestureDetector: null,\n ScrollView: null,\n }\n }\n return g[GLOBAL_KEY]\n}\n\nexport function isGestureHandlerEnabled(): boolean {\n return getGlobalState().enabled\n}\n\nexport function getGestureHandlerState(): GestureState {\n return getGlobalState()\n}\n\nexport function setGestureHandlerState(updates: Partial<GestureState>): void {\n const state = getGlobalState()\n Object.assign(state, updates)\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamagui/native
|
|
3
|
+
*
|
|
4
|
+
* Native setup modules for Tamagui. Import these at the top of your app entry point.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* // In your app entry (index.js or App.tsx)
|
|
9
|
+
* import '@tamagui/native/setup-portal'
|
|
10
|
+
* import '@tamagui/native/setup-gesture-handler'
|
|
11
|
+
* import '@tamagui/native/setup-worklets'
|
|
12
|
+
*
|
|
13
|
+
* // Then use Tamagui components normally
|
|
14
|
+
* // Sheet will automatically use native gestures when available
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export { getNativePortalState, setNativePortalState } from "./portalState";
|
|
18
|
+
export type { NativePortalState } from "./portalState";
|
|
19
|
+
export { NativePortal, NativePortalHost, NativePortalProvider } from "./components";
|
|
20
|
+
export type { NativePortalProps, NativePortalHostProps, NativePortalProviderProps } from "./components";
|
|
21
|
+
export { isGestureHandlerEnabled, getGestureHandlerState, setGestureHandlerState } from "./gestureState";
|
|
22
|
+
export type { GestureState } from "./gestureState";
|
|
23
|
+
export { isWorkletsEnabled, getWorkletsState } from "./workletsState";
|
|
24
|
+
export type { WorkletsState } from "./workletsState";
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": ";;;;;;;;;;;;;;;;AAkBA,SAAS,sBAAsB,4BAA4B;AAC3D,cAAc,yBAAyB;AAEvC,SAAS,cAAc,kBAAkB,4BAA4B;AACrE,cACE,mBACA,uBACA,iCACK;AAGP,SACE,yBACA,wBACA,8BACK;AACP,cAAc,oBAAoB;AAGlC,SAAS,mBAAmB,wBAAwB;AACpD,cAAc,qBAAqB",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/index.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"/**\n * @tamagui/native\n *\n * Native setup modules for Tamagui. Import these at the top of your app entry point.\n *\n * @example\n * ```tsx\n * // In your app entry (index.js or App.tsx)\n * import '@tamagui/native/setup-portal'\n * import '@tamagui/native/setup-gesture-handler'\n * import '@tamagui/native/setup-worklets'\n *\n * // Then use Tamagui components normally\n * // Sheet will automatically use native gestures when available\n * ```\n */\n\n// portal state exports (safe - no side effects)\nexport { getNativePortalState, setNativePortalState } from './portalState'\nexport type { NativePortalState } from './portalState'\n\nexport { NativePortal, NativePortalHost, NativePortalProvider } from './components'\nexport type {\n NativePortalProps,\n NativePortalHostProps,\n NativePortalProviderProps,\n} from './components'\n\n// gesture handler state exports (safe - no side effects)\nexport {\n isGestureHandlerEnabled,\n getGestureHandlerState,\n setGestureHandlerState,\n} from './gestureState'\nexport type { GestureState } from './gestureState'\n\n// worklets state exports (safe - no side effects)\nexport { isWorkletsEnabled, getWorkletsState } from './workletsState'\nexport type { WorkletsState } from './workletsState'\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type NativePortalState = {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
type: "teleport" | "legacy" | null;
|
|
4
|
+
};
|
|
5
|
+
export declare function setNativePortalState(newState: NativePortalState);
|
|
6
|
+
export declare function getNativePortalState(): NativePortalState;
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=portalState.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,YAAY,oBAAoB;CAC9B;CACA,MAAM,aAAa;;AAKrB,OAAO,iBAAS,qBAAqB,UAAU;AAI/C,OAAO,iBAAS,wBAAwB",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/portalState.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"export type NativePortalState = {\n enabled: boolean\n type: 'teleport' | 'legacy' | null\n}\n\nlet state: NativePortalState = { enabled: false, type: null }\n\nexport function setNativePortalState(newState: NativePortalState) {\n state = newState\n}\n\nexport function getNativePortalState(): NativePortalState {\n return state\n}\n// retrigger ci\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/setup-gesture-handler.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"/**\n * Setup gesture handler for Tamagui native components.\n *\n * Simply import this module at the top of your app entry point:\n *\n * @example\n * ```tsx\n * import '@tamagui/native/setup-gesture-handler'\n * ```\n *\n * This automatically detects and configures react-native-gesture-handler\n * for use with Sheet and other gesture-aware components.\n */\n\nimport { setGestureHandlerState } from './gestureState'\n\nfunction setup() {\n const g = globalThis as any\n if (g.__tamagui_native_gesture_setup_complete) {\n return\n }\n g.__tamagui_native_gesture_setup_complete = true\n\n try {\n // dynamically require RNGH - it should already be imported by the app\n const rngh = require('react-native-gesture-handler')\n const { Gesture, GestureDetector, ScrollView } = rngh\n\n if (Gesture && GestureDetector) {\n setGestureHandlerState({\n enabled: true,\n Gesture,\n GestureDetector,\n ScrollView: ScrollView || null,\n })\n\n // also set on the legacy key for backward compat with @tamagui/sheet\n g.__tamagui_sheet_gesture_state__ = {\n enabled: true,\n Gesture,\n GestureDetector,\n ScrollView: ScrollView || null,\n }\n }\n } catch {\n // RNGH not available, that's fine\n }\n}\n\n// run setup immediately on import\nsetup()\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AA8DA,OAAO,cAAM",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/setup-portal.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"/**\n * Setup native portal support for Tamagui.\n *\n * Simply import this module at the top of your app entry point:\n *\n * @example\n * ```tsx\n * import '@tamagui/native/setup-portal'\n * ```\n *\n * This automatically detects and configures react-native-teleport for portals.\n * Falls back to legacy RN shims if teleport is not installed.\n */\n\nimport { setNativePortalState } from './portalState'\n\nconst IS_FABRIC =\n typeof global !== 'undefined' &&\n Boolean((global as any)._IS_FABRIC ?? (global as any).nativeFabricUIManager)\n\nfunction setup() {\n const g = globalThis as any\n if (g.__tamagui_native_portal_setup) return\n g.__tamagui_native_portal_setup = true\n\n // try teleport first (preferred)\n try {\n const teleport = require('react-native-teleport')\n if (teleport?.Portal && teleport?.PortalHost && teleport?.PortalProvider) {\n g.__tamagui_teleport = teleport\n setNativePortalState({ enabled: true, type: 'teleport' })\n return\n }\n } catch {\n // teleport not installed, try legacy\n }\n\n // fall back to legacy RN shims approach\n if (IS_FABRIC) {\n try {\n const mod = require('react-native/Libraries/Renderer/shims/ReactFabric')\n g.__tamagui_portal_create = mod?.default?.createPortal ?? mod.createPortal\n setNativePortalState({ enabled: true, type: 'legacy' })\n } catch (err) {\n console.info(`Note: error importing fabric portal, native portals disabled`, err)\n }\n return\n }\n\n try {\n const mod = require('react-native/Libraries/Renderer/shims/ReactNative')\n g.__tamagui_portal_create = mod?.default?.createPortal ?? mod.createPortal\n setNativePortalState({ enabled: true, type: 'legacy' })\n } catch (err) {\n console.info(`Note: error importing native portal, native portals disabled`, err)\n }\n}\n\n// run setup immediately on import\nsetup()\n\n// keep the function export for backward compatibility\nexport const setupNativePortal = setup\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/setup-worklets.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"/**\n * Setup worklets for Tamagui native components.\n *\n * Simply import this module at the top of your app entry point:\n *\n * @example\n * ```tsx\n * import '@tamagui/native/setup-worklets'\n * ```\n *\n * This automatically detects and configures react-native-worklets-core\n * for use with Sheet and other components that benefit from synchronous\n * native-thread execution.\n *\n * When combined with setup-gesture-handler, Sheet gets native-quality\n * gesture coordination between sheet dragging and scroll views.\n *\n * @see https://docs.swmansion.com/react-native-worklets/docs/\n */\n\nimport { setWorkletsState } from './workletsState'\n\nfunction setup() {\n const g = globalThis as any\n if (g.__tamagui_native_worklets_setup_complete) {\n return\n }\n g.__tamagui_native_worklets_setup_complete = true\n\n try {\n // dynamically require worklets-core\n const worklets = require('react-native-worklets-core')\n\n if (worklets) {\n setWorkletsState({\n enabled: true,\n Worklets: worklets.Worklets,\n useRunOnJS: worklets.useRunOnJS,\n useWorklet: worklets.useWorklet,\n createWorkletContextValue: worklets.createWorkletContextValue,\n })\n }\n } catch {\n // worklets not available, that's fine - will fall back to JS thread\n }\n}\n\n// run setup immediately on import\nsetup()\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface WorkletsState {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
Worklets: any;
|
|
4
|
+
useRunOnJS: any;
|
|
5
|
+
useWorklet: any;
|
|
6
|
+
createWorkletContextValue: any;
|
|
7
|
+
}
|
|
8
|
+
export declare function isWorkletsEnabled(): boolean;
|
|
9
|
+
export declare function getWorkletsState(): WorkletsState;
|
|
10
|
+
export declare function setWorkletsState(updates: Partial<WorkletsState>): void;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=workletsState.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAEA,iBAAiB,cAAc;CAC7B;CACA;CACA;CACA;CACA;;AAiBF,OAAO,iBAAS;AAIhB,OAAO,iBAAS,oBAAoB;AAIpC,OAAO,iBAAS,iBAAiB,SAAS,QAAQ",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/workletsState.ts"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"const GLOBAL_KEY = '__tamagui_native_worklets_state__'\n\nexport interface WorkletsState {\n enabled: boolean\n Worklets: any\n useRunOnJS: any\n useWorklet: any\n createWorkletContextValue: any\n}\n\nfunction getGlobalState(): WorkletsState {\n const g = globalThis as any\n if (!g[GLOBAL_KEY]) {\n g[GLOBAL_KEY] = {\n enabled: false,\n Worklets: null,\n useRunOnJS: null,\n useWorklet: null,\n createWorkletContextValue: null,\n }\n }\n return g[GLOBAL_KEY]\n}\n\nexport function isWorkletsEnabled(): boolean {\n return getGlobalState().enabled\n}\n\nexport function getWorkletsState(): WorkletsState {\n return getGlobalState()\n}\n\nexport function setWorkletsState(updates: Partial<WorkletsState>): void {\n const state = getGlobalState()\n Object.assign(state, updates)\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|