@tamagui/fake-react-native 3.0.0-beta.1479.1 → 3.0.0-beta.1540.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/fake-react-native",
3
- "version": "3.0.0-beta.1479.1",
3
+ "version": "3.0.0-beta.1540.1",
4
4
  "license": "MIT",
5
5
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
6
6
  "main": "index.js",
@@ -11,11 +11,32 @@
11
11
  "module": "./index.mjs",
12
12
  "import": "./index.mjs",
13
13
  "require": "./index.js"
14
+ },
15
+ "./pressability": "./pressability.js",
16
+ "./pressEvent": {
17
+ "types": "./pressEvent.d.ts",
18
+ "default": "./pressEvent.js"
14
19
  }
15
20
  },
16
21
  "publishConfig": {
17
22
  "access": "public"
18
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
+ },
19
40
  "repository": {
20
41
  "type": "git",
21
42
  "url": "git+https://github.com/tamagui/tamagui.git",
@@ -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
@@ -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