@tamagui/fake-react-native 2.7.7 → 3.0.0-0.canary.1791056644527
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/index.js +57 -1
- package/index.mjs +18 -0
- package/package.json +25 -2
- package/pressEvent.d.ts +18 -0
- package/pressEvent.js +24 -0
- package/pressability.js +62 -0
package/index.js
CHANGED
|
@@ -18,24 +18,68 @@ const emtpyComponent = () => null
|
|
|
18
18
|
// Mock usePressability for testing - returns empty event handlers
|
|
19
19
|
const usePressabilityMock = () => ({})
|
|
20
20
|
|
|
21
|
+
// real context: consumers (tamagui's useChildren) call React.useContext on it,
|
|
22
|
+
// the proxyWorm fallback object would break that
|
|
23
|
+
const TextAncestorContext = React.createContext(false)
|
|
24
|
+
const Animated = {
|
|
25
|
+
createAnimatedComponent: (Component) => Component,
|
|
26
|
+
}
|
|
27
|
+
const Keyboard = {
|
|
28
|
+
addListener: () => ({ remove: () => {} }),
|
|
29
|
+
removeAllListeners: () => {},
|
|
30
|
+
dismiss: () => {},
|
|
31
|
+
}
|
|
32
|
+
const useWindowDimensions = () => ({
|
|
33
|
+
width: 1024,
|
|
34
|
+
height: 768,
|
|
35
|
+
scale: 2,
|
|
36
|
+
fontScale: 1,
|
|
37
|
+
})
|
|
38
|
+
const PanResponder = {
|
|
39
|
+
create: (handlers) => ({ panHandlers: handlers }),
|
|
40
|
+
}
|
|
41
|
+
const TurboModuleRegistry = {
|
|
42
|
+
get: () => null,
|
|
43
|
+
}
|
|
44
|
+
const PixelRatio = {
|
|
45
|
+
get: () => 2,
|
|
46
|
+
getFontScale: () => 1,
|
|
47
|
+
getPixelSizeForLayoutSize: (size) => Math.round(size * 2),
|
|
48
|
+
roundToNearestPixel: (size) => Math.round(size * 2) / 2,
|
|
49
|
+
}
|
|
50
|
+
const codegenNativeCommands = () => ({})
|
|
51
|
+
const codegenNativeComponent = (name) => createMockComponent(name)
|
|
52
|
+
|
|
21
53
|
function proxyWorm() {
|
|
22
54
|
return new Proxy(
|
|
23
55
|
{
|
|
24
56
|
StyleSheet: {
|
|
25
57
|
create() {},
|
|
26
58
|
},
|
|
59
|
+
unstable_TextAncestorContext: TextAncestorContext,
|
|
27
60
|
Platform: {
|
|
28
61
|
OS: 'web',
|
|
62
|
+
select: (options) => options.web ?? options.default,
|
|
29
63
|
},
|
|
30
64
|
Image: emtpyComponent,
|
|
31
65
|
View: createMockComponent('View'),
|
|
32
66
|
Text: createMockComponent('Text'),
|
|
33
67
|
TextInput: createMockComponent('TextInput'),
|
|
34
68
|
ScrollView: createMockComponent('ScrollView'),
|
|
69
|
+
FlatList: createMockComponent('FlatList'),
|
|
70
|
+
Pressable: createMockComponent('Pressable'),
|
|
71
|
+
Animated,
|
|
72
|
+
NativeModules: {},
|
|
73
|
+
PanResponder,
|
|
74
|
+
TurboModuleRegistry,
|
|
75
|
+
PixelRatio,
|
|
76
|
+
processColor: (color) => color,
|
|
35
77
|
Dimensions: {
|
|
36
|
-
get: () => ({ width: 1024, height: 768 }),
|
|
78
|
+
get: () => ({ width: 1024, height: 768, scale: 2, fontScale: 1 }),
|
|
37
79
|
addEventListener: () => ({ remove: () => {} }),
|
|
38
80
|
},
|
|
81
|
+
useWindowDimensions,
|
|
82
|
+
Keyboard,
|
|
39
83
|
Appearance: {
|
|
40
84
|
getColorScheme: () => 'light',
|
|
41
85
|
addChangeListener: () => {},
|
|
@@ -73,5 +117,17 @@ module.exports.View = proxy.View
|
|
|
73
117
|
module.exports.Text = proxy.Text
|
|
74
118
|
module.exports.TextInput = proxy.TextInput
|
|
75
119
|
module.exports.ScrollView = proxy.ScrollView
|
|
120
|
+
module.exports.FlatList = proxy.FlatList
|
|
121
|
+
module.exports.Pressable = proxy.Pressable
|
|
122
|
+
module.exports.Animated = proxy.Animated
|
|
123
|
+
module.exports.NativeModules = proxy.NativeModules
|
|
124
|
+
module.exports.PanResponder = proxy.PanResponder
|
|
125
|
+
module.exports.TurboModuleRegistry = proxy.TurboModuleRegistry
|
|
126
|
+
module.exports.PixelRatio = PixelRatio
|
|
127
|
+
module.exports.processColor = proxy.processColor
|
|
76
128
|
module.exports.Dimensions = proxy.Dimensions
|
|
129
|
+
module.exports.useWindowDimensions = useWindowDimensions
|
|
130
|
+
module.exports.Keyboard = Keyboard
|
|
77
131
|
module.exports.Appearance = proxy.Appearance
|
|
132
|
+
module.exports.codegenNativeCommands = codegenNativeCommands
|
|
133
|
+
module.exports.codegenNativeComponent = codegenNativeComponent
|
package/index.mjs
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
1
3
|
const emtpyComponent = () => null
|
|
2
4
|
|
|
5
|
+
// real context: consumers (tamagui's useChildren) call React.useContext on it,
|
|
6
|
+
// the proxyWorm fallback object would break that
|
|
7
|
+
const TextAncestorContext = React.createContext(false)
|
|
8
|
+
|
|
3
9
|
function proxyWorm() {
|
|
4
10
|
return new Proxy(
|
|
5
11
|
{
|
|
6
12
|
StyleSheet: {
|
|
7
13
|
create() {},
|
|
8
14
|
},
|
|
15
|
+
unstable_TextAncestorContext: TextAncestorContext,
|
|
9
16
|
Platform: {
|
|
10
17
|
OS: 'web',
|
|
11
18
|
},
|
|
@@ -15,8 +22,15 @@ function proxyWorm() {
|
|
|
15
22
|
TextInput: emtpyComponent,
|
|
16
23
|
ScrollView: emtpyComponent,
|
|
17
24
|
Dimensions: {
|
|
25
|
+
get: () => ({ width: 1024, height: 768, scale: 2, fontScale: 1 }),
|
|
18
26
|
addEventListener(cb) {},
|
|
19
27
|
},
|
|
28
|
+
PixelRatio: {
|
|
29
|
+
get: () => 2,
|
|
30
|
+
getFontScale: () => 1,
|
|
31
|
+
getPixelSizeForLayoutSize: (size) => Math.round(size * 2),
|
|
32
|
+
roundToNearestPixel: (size) => Math.round(size * 2) / 2,
|
|
33
|
+
},
|
|
20
34
|
Appearance: {
|
|
21
35
|
getColorScheme: () => 'light',
|
|
22
36
|
addChangeListener: () => {},
|
|
@@ -46,12 +60,16 @@ export const Text = proxy.Text
|
|
|
46
60
|
export const TextInput = proxy.TextInput
|
|
47
61
|
export const ScrollView = proxy.ScrollView
|
|
48
62
|
export const Dimensions = proxy.Dimensions
|
|
63
|
+
export const PixelRatio = proxy.PixelRatio
|
|
49
64
|
export const Pressable = proxy.Pressable
|
|
50
65
|
export const Animated = proxy.Animated
|
|
51
66
|
export const Easing = proxy.Easing
|
|
52
67
|
export const Appearance = proxy.Appearance
|
|
53
68
|
export const findNodeHandle = proxy.findNodeHandle
|
|
54
69
|
export const unstable_batchedUpdates = proxy.unstable_batchedUpdates
|
|
70
|
+
export const unstable_TextAncestorContext = proxy.unstable_TextAncestorContext
|
|
71
|
+
export const codegenNativeCommands = () => ({})
|
|
72
|
+
export const codegenNativeComponent = () => emtpyComponent
|
|
55
73
|
|
|
56
74
|
// Default export
|
|
57
75
|
export default proxy
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/fake-react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-0.canary.1791056644527",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"module": "index.mjs",
|
|
@@ -10,14 +11,36 @@
|
|
|
10
11
|
"module": "./index.mjs",
|
|
11
12
|
"import": "./index.mjs",
|
|
12
13
|
"require": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"./pressability": "./pressability.js",
|
|
16
|
+
"./pressEvent": {
|
|
17
|
+
"types": "./pressEvent.d.ts",
|
|
18
|
+
"default": "./pressEvent.js"
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"publishConfig": {
|
|
16
22
|
"access": "public"
|
|
17
23
|
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@babel/core": "*",
|
|
26
|
+
"@react-native/babel-preset": "*",
|
|
27
|
+
"react-native": "*"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@babel/core": {
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"@react-native/babel-preset": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"react-native": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
18
40
|
"repository": {
|
|
19
41
|
"type": "git",
|
|
20
42
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
21
43
|
"directory": "code/packages/fake-react-native"
|
|
22
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"releaseSourceCommit": "e09267246167b52afd620a498678f5cce456cb5a"
|
|
23
46
|
}
|
package/pressEvent.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// a responder event for react native press tests: the view measurement and
|
|
2
|
+
// touch coordinates its press handler reads, with move and cancel support.
|
|
3
|
+
export declare function pressEvent(
|
|
4
|
+
pageX?: number,
|
|
5
|
+
pageY?: number
|
|
6
|
+
): {
|
|
7
|
+
currentTarget: { measure(callback: (...bounds: number[]) => void): void }
|
|
8
|
+
target: { measure(callback: (...bounds: number[]) => void): void }
|
|
9
|
+
nativeEvent: {
|
|
10
|
+
pageX: number
|
|
11
|
+
pageY: number
|
|
12
|
+
timestamp: number
|
|
13
|
+
touches: { pageX: number; pageY: number }[]
|
|
14
|
+
changedTouches: { pageX: number; pageY: number }[]
|
|
15
|
+
}
|
|
16
|
+
persist(): void
|
|
17
|
+
stopPropagation(): void
|
|
18
|
+
}
|
package/pressEvent.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// responder fixtures include the native view measurement and touch coordinates
|
|
2
|
+
// consumed by react native's press handler, including move and cancel events.
|
|
3
|
+
function pressEvent(pageX = 10, pageY = 10) {
|
|
4
|
+
const target = {
|
|
5
|
+
measure(callback) {
|
|
6
|
+
callback(0, 0, 100, 100, 0, 0)
|
|
7
|
+
},
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
currentTarget: target,
|
|
11
|
+
target,
|
|
12
|
+
nativeEvent: {
|
|
13
|
+
pageX,
|
|
14
|
+
pageY,
|
|
15
|
+
timestamp: Date.now(),
|
|
16
|
+
touches: [{ pageX, pageY }],
|
|
17
|
+
changedTouches: [{ pageX, pageY }],
|
|
18
|
+
},
|
|
19
|
+
persist() {},
|
|
20
|
+
stopPropagation() {},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.pressEvent = pressEvent
|
package/pressability.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { readFileSync } = require('node:fs')
|
|
2
|
+
const { dirname, join, resolve } = require('node:path')
|
|
3
|
+
const Module = require('node:module')
|
|
4
|
+
const { transformSync } = require('@babel/core')
|
|
5
|
+
|
|
6
|
+
// run react native's actual press state machine in native tests. only the
|
|
7
|
+
// platform bindings are mocked; geometry, timers and cancellation stay real.
|
|
8
|
+
// published so any native test setup, in or out of this repo, aliases
|
|
9
|
+
// react-native/Libraries/Pressability/usePressability to this one file.
|
|
10
|
+
const root = dirname(require.resolve('react-native/package.json'))
|
|
11
|
+
const platform = require('./index.js').Platform
|
|
12
|
+
const bindings = new Map([
|
|
13
|
+
[join(root, 'Libraries/Utilities/Platform.js'), platform],
|
|
14
|
+
[
|
|
15
|
+
join(root, 'Libraries/ReactNative/UIManager.js'),
|
|
16
|
+
{
|
|
17
|
+
measure() {
|
|
18
|
+
throw new Error('native press tests must provide a measurable responder')
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
[join(root, 'Libraries/Components/Sound/SoundManager.js'), { playTouchSound() {} }],
|
|
23
|
+
[
|
|
24
|
+
join(root, 'src/private/featureflags/ReactNativeFeatureFlags.js'),
|
|
25
|
+
{
|
|
26
|
+
shouldPressibilityUseW3CPointerEventsForHover: () => false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
])
|
|
30
|
+
const cache = new Map()
|
|
31
|
+
|
|
32
|
+
function load(filename) {
|
|
33
|
+
if (bindings.has(filename)) return bindings.get(filename)
|
|
34
|
+
if (cache.has(filename)) return cache.get(filename).exports
|
|
35
|
+
const compiled = new Module(filename, module)
|
|
36
|
+
compiled.paths = Module._nodeModulePaths(dirname(filename))
|
|
37
|
+
compiled.require = (request) => {
|
|
38
|
+
if (request.startsWith('.')) {
|
|
39
|
+
const path = resolve(dirname(filename), request)
|
|
40
|
+
return load(path.endsWith('.js') ? path : path + '.js')
|
|
41
|
+
}
|
|
42
|
+
return Module.prototype.require.call(compiled, request)
|
|
43
|
+
}
|
|
44
|
+
cache.set(filename, compiled)
|
|
45
|
+
const output = transformSync(readFileSync(filename, 'utf8'), {
|
|
46
|
+
filename,
|
|
47
|
+
babelrc: false,
|
|
48
|
+
configFile: false,
|
|
49
|
+
presets: [
|
|
50
|
+
[require.resolve('@react-native/babel-preset'), { enableBabelRuntime: false }],
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
Function(
|
|
54
|
+
'require',
|
|
55
|
+
'module',
|
|
56
|
+
'exports',
|
|
57
|
+
output.code
|
|
58
|
+
)(compiled.require, compiled, compiled.exports)
|
|
59
|
+
return compiled.exports
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = load(join(root, 'Libraries/Pressability/usePressability.js')).default
|