Skip to content

Commit a097be0

Browse files
migueldaiprejakex7
andauthored
fix: web exports on prepare file (#2430)
# Summary Fixes #2401 Fixes error in `prepare.ts` file that imports `hasTouchableProperty` from a '.' file. It's probably related to the way ESM works, I'm not sure. I base it on [PR](#2312) ``` (0 , _.hasTouchableProperty) is not a function TypeError: (0 , _.hasTouchableProperty) is not a function at prepare ``` <img width="860" alt="image" src="https://github.com/user-attachments/assets/43f91d13-115c-4daf-9269-92ae49b44972"> ## Test Plan Should work without error on web https://github.com/user-attachments/assets/4f7143bf-06f8-4684-844c-d5a147837adb ## Compatibility | OS | Implemented | | ------- | :---------: | | Web | ✅ | ## Checklist - [X] I have tested this on a web project --------- Co-authored-by: Jakub Grzywacz <[email protected]>
1 parent 7ab35cd commit a097be0

File tree

5 files changed

+78
-70
lines changed

5 files changed

+78
-70
lines changed

src/web/WebShape.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import { BaseProps } from './types';
99
import { prepare } from './utils/prepare';
1010
import { convertInt32ColorToRGBA } from './utils/convertInt32Color';
11-
import { camelCaseToDashed, hasTouchableProperty, remeasure } from './utils';
11+
import { camelCaseToDashed, remeasure } from './utils';
12+
import { hasTouchableProperty } from './utils/hasProperty';
1213
import SvgTouchableMixin from '../lib/SvgTouchableMixin';
1314

1415
export class WebShape<

src/web/utils/hasProperty.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { BaseProps } from '../types';
2+
3+
export function hasTouchableProperty(props: BaseProps): boolean {
4+
return !!(
5+
props.onPress ||
6+
props.onPressIn ||
7+
props.onPressOut ||
8+
props.onLongPress
9+
);
10+
}

src/web/utils/index.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,7 @@
1-
import { BaseProps } from '../types';
2-
import type { TransformProps } from '../../lib/extract/types';
3-
import {
4-
transformsArrayToProps,
5-
TransformsStyleArray,
6-
} from '../../lib/extract/extractTransform';
7-
8-
export const hasTouchableProperty = (props: BaseProps) =>
9-
props.onPress || props.onPressIn || props.onPressOut || props.onLongPress;
10-
111
export const camelCaseToDashed = (camelCase: string) => {
122
return camelCase.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
133
};
144

15-
function stringifyTransformProps(transformProps: TransformProps) {
16-
const transformArray = [];
17-
if (transformProps.translate != null) {
18-
transformArray.push(`translate(${transformProps.translate})`);
19-
}
20-
if (transformProps.translateX != null || transformProps.translateY != null) {
21-
transformArray.push(
22-
`translate(${transformProps.translateX || 0}, ${
23-
transformProps.translateY || 0
24-
})`
25-
);
26-
}
27-
if (transformProps.scale != null) {
28-
transformArray.push(`scale(${transformProps.scale})`);
29-
}
30-
if (transformProps.scaleX != null || transformProps.scaleY != null) {
31-
transformArray.push(
32-
`scale(${transformProps.scaleX || 1}, ${transformProps.scaleY || 1})`
33-
);
34-
}
35-
// rotation maps to rotate, not to collide with the text rotate attribute (which acts per glyph rather than block)
36-
if (transformProps.rotation != null) {
37-
transformArray.push(`rotate(${transformProps.rotation})`);
38-
}
39-
if (transformProps.skewX != null) {
40-
transformArray.push(`skewX(${transformProps.skewX})`);
41-
}
42-
if (transformProps.skewY != null) {
43-
transformArray.push(`skewY(${transformProps.skewY})`);
44-
}
45-
return transformArray;
46-
}
47-
48-
export function parseTransformProp(
49-
transform: TransformProps['transform'],
50-
props?: BaseProps
51-
) {
52-
const transformArray: string[] = [];
53-
54-
props && transformArray.push(...stringifyTransformProps(props));
55-
56-
if (Array.isArray(transform)) {
57-
if (typeof transform[0] === 'number') {
58-
transformArray.push(`matrix(${transform.join(' ')})`);
59-
} else {
60-
const stringifiedProps = transformsArrayToProps(
61-
// @ts-expect-error FIXME
62-
transform as TransformsStyleArray
63-
);
64-
transformArray.push(...stringifyTransformProps(stringifiedProps));
65-
}
66-
} else if (typeof transform === 'string') {
67-
transformArray.push(transform);
68-
}
69-
70-
return transformArray.length ? transformArray.join(' ') : undefined;
71-
}
72-
735
export const getBoundingClientRect = (node: SVGElement) => {
746
if (node) {
757
const isElement = node.nodeType === 1; /* Node.ELEMENT_NODE */

src/web/utils/parseTransform.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import type { TransformProps } from '../../lib/extract/types';
2+
import {
3+
transformsArrayToProps,
4+
TransformsStyleArray,
5+
} from '../../lib/extract/extractTransform';
6+
import type { BaseProps } from '../types';
7+
8+
export function parseTransformProp(
9+
transform: TransformProps['transform'],
10+
props?: BaseProps
11+
) {
12+
const transformArray: string[] = [];
13+
14+
props && transformArray.push(...stringifyTransformProps(props));
15+
16+
if (Array.isArray(transform)) {
17+
if (typeof transform[0] === 'number') {
18+
transformArray.push(`matrix(${transform.join(' ')})`);
19+
} else {
20+
const stringifiedProps = transformsArrayToProps(
21+
// @ts-expect-error FIXME
22+
transform as TransformsStyleArray
23+
);
24+
transformArray.push(...stringifyTransformProps(stringifiedProps));
25+
}
26+
} else if (typeof transform === 'string') {
27+
transformArray.push(transform);
28+
}
29+
30+
return transformArray.length ? transformArray.join(' ') : undefined;
31+
}
32+
33+
export function stringifyTransformProps(transformProps: TransformProps) {
34+
const transformArray = [];
35+
if (transformProps.translate != null) {
36+
transformArray.push(`translate(${transformProps.translate})`);
37+
}
38+
if (transformProps.translateX != null || transformProps.translateY != null) {
39+
transformArray.push(
40+
`translate(${transformProps.translateX || 0}, ${
41+
transformProps.translateY || 0
42+
})`
43+
);
44+
}
45+
if (transformProps.scale != null) {
46+
transformArray.push(`scale(${transformProps.scale})`);
47+
}
48+
if (transformProps.scaleX != null || transformProps.scaleY != null) {
49+
transformArray.push(
50+
`scale(${transformProps.scaleX || 1}, ${transformProps.scaleY || 1})`
51+
);
52+
}
53+
// rotation maps to rotate, not to collide with the text rotate attribute (which acts per glyph rather than block)
54+
if (transformProps.rotation != null) {
55+
transformArray.push(`rotate(${transformProps.rotation})`);
56+
}
57+
if (transformProps.skewX != null) {
58+
transformArray.push(`skewX(${transformProps.skewX})`);
59+
}
60+
if (transformProps.skewY != null) {
61+
transformArray.push(`skewY(${transformProps.skewY})`);
62+
}
63+
return transformArray;
64+
}

src/web/utils/prepare.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
} from 'react-native';
55
import { BaseProps } from '../types';
66
import { WebShape } from '../WebShape';
7-
import { hasTouchableProperty, parseTransformProp } from '.';
7+
import { hasTouchableProperty } from './hasProperty';
8+
import { parseTransformProp } from './parseTransform';
89
import { resolve } from '../../lib/resolve';
910
import { NumberProp } from '../../lib/extract/types';
1011
import { resolveAssetUri } from '../../lib/resolveAssetUri';

0 commit comments

Comments
 (0)