@tamagui/fake-react-native 3.0.0-beta.924.1 → 3.0.1
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 +11 -1
- package/index.mjs +12 -0
- package/index.node.mjs +10 -0
- package/package.json +26 -3
- package/pressEvent.d.ts +18 -0
- package/pressEvent.js +24 -0
- package/pressability.js +62 -0
package/index.js
CHANGED
|
@@ -41,6 +41,12 @@ const PanResponder = {
|
|
|
41
41
|
const TurboModuleRegistry = {
|
|
42
42
|
get: () => null,
|
|
43
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
|
+
}
|
|
44
50
|
const codegenNativeCommands = () => ({})
|
|
45
51
|
const codegenNativeComponent = (name) => createMockComponent(name)
|
|
46
52
|
|
|
@@ -66,9 +72,10 @@ function proxyWorm() {
|
|
|
66
72
|
NativeModules: {},
|
|
67
73
|
PanResponder,
|
|
68
74
|
TurboModuleRegistry,
|
|
75
|
+
PixelRatio,
|
|
69
76
|
processColor: (color) => color,
|
|
70
77
|
Dimensions: {
|
|
71
|
-
get: () => ({ width: 1024, height: 768 }),
|
|
78
|
+
get: () => ({ width: 1024, height: 768, scale: 2, fontScale: 1 }),
|
|
72
79
|
addEventListener: () => ({ remove: () => {} }),
|
|
73
80
|
},
|
|
74
81
|
useWindowDimensions,
|
|
@@ -116,6 +123,7 @@ module.exports.Animated = proxy.Animated
|
|
|
116
123
|
module.exports.NativeModules = proxy.NativeModules
|
|
117
124
|
module.exports.PanResponder = proxy.PanResponder
|
|
118
125
|
module.exports.TurboModuleRegistry = proxy.TurboModuleRegistry
|
|
126
|
+
module.exports.PixelRatio = PixelRatio
|
|
119
127
|
module.exports.processColor = proxy.processColor
|
|
120
128
|
module.exports.Dimensions = proxy.Dimensions
|
|
121
129
|
module.exports.useWindowDimensions = useWindowDimensions
|
|
@@ -123,3 +131,5 @@ module.exports.Keyboard = Keyboard
|
|
|
123
131
|
module.exports.Appearance = proxy.Appearance
|
|
124
132
|
module.exports.codegenNativeCommands = codegenNativeCommands
|
|
125
133
|
module.exports.codegenNativeComponent = codegenNativeComponent
|
|
134
|
+
// load the RN hook only when native code calls it; RN is an optional peer.
|
|
135
|
+
module.exports.usePressability = (...args) => require('./pressability')(...args)
|
package/index.mjs
CHANGED
|
@@ -22,8 +22,15 @@ function proxyWorm() {
|
|
|
22
22
|
TextInput: emtpyComponent,
|
|
23
23
|
ScrollView: emtpyComponent,
|
|
24
24
|
Dimensions: {
|
|
25
|
+
get: () => ({ width: 1024, height: 768, scale: 2, fontScale: 1 }),
|
|
25
26
|
addEventListener(cb) {},
|
|
26
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
|
+
},
|
|
27
34
|
Appearance: {
|
|
28
35
|
getColorScheme: () => 'light',
|
|
29
36
|
addChangeListener: () => {},
|
|
@@ -43,6 +50,9 @@ function proxyWorm() {
|
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
const proxy = proxyWorm()
|
|
53
|
+
// browser entry exposes the hook call shape; Node ESM uses the native loader.
|
|
54
|
+
const usePressability = () => ({})
|
|
55
|
+
proxy.usePressability = usePressability
|
|
46
56
|
|
|
47
57
|
// Named exports that can be tree-shaken
|
|
48
58
|
export const Platform = proxy.Platform
|
|
@@ -53,6 +63,7 @@ export const Text = proxy.Text
|
|
|
53
63
|
export const TextInput = proxy.TextInput
|
|
54
64
|
export const ScrollView = proxy.ScrollView
|
|
55
65
|
export const Dimensions = proxy.Dimensions
|
|
66
|
+
export const PixelRatio = proxy.PixelRatio
|
|
56
67
|
export const Pressable = proxy.Pressable
|
|
57
68
|
export const Animated = proxy.Animated
|
|
58
69
|
export const Easing = proxy.Easing
|
|
@@ -62,6 +73,7 @@ export const unstable_batchedUpdates = proxy.unstable_batchedUpdates
|
|
|
62
73
|
export const unstable_TextAncestorContext = proxy.unstable_TextAncestorContext
|
|
63
74
|
export const codegenNativeCommands = () => ({})
|
|
64
75
|
export const codegenNativeComponent = () => emtpyComponent
|
|
76
|
+
export { usePressability }
|
|
65
77
|
|
|
66
78
|
// Default export
|
|
67
79
|
export default proxy
|
package/index.node.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import proxy from './index.mjs'
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url)
|
|
5
|
+
const usePressability = (...args) => require('./pressability.js')(...args)
|
|
6
|
+
proxy.usePressability = usePressability
|
|
7
|
+
|
|
8
|
+
export * from './index.mjs'
|
|
9
|
+
export { usePressability }
|
|
10
|
+
export default proxy
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/fake-react-native",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"module": "index.mjs",
|
|
@@ -8,16 +9,38 @@
|
|
|
8
9
|
".": {
|
|
9
10
|
"browser": "./index.mjs",
|
|
10
11
|
"module": "./index.mjs",
|
|
11
|
-
"import": "./index.mjs",
|
|
12
|
+
"import": "./index.node.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": "c156b7cc55e5a6cc5883ebc8189720850ac32dbd"
|
|
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
|