Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/benchmarks/perf/mocks/AnimatedNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const animatedNodeMarker = Symbol('AnimatedNode');

export function createAnimatedNode(config) {
return Object.defineProperty({ ...config }, animatedNodeMarker, {
value: true
});
}

export default class AnimatedNode {
static [Symbol.hasInstance](value) {
return Boolean(value?.[animatedNodeMarker]);
}
}
4 changes: 3 additions & 1 deletion packages/benchmarks/perf/mocks/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* React Native mock for Node.js benchmarks
*/

import { createAnimatedNode } from './AnimatedNode';

export const AccessibilityInfo = {
addEventListener: () => ({
remove: () => {}
Expand All @@ -25,7 +27,7 @@ export const Animated = {
Text: 'Animated.Text',
Value: () => {
return {
interpolate: (value) => value
interpolate: (value) => createAnimatedNode(value)
};
},
timing: () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/benchmarks/perf/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const config = [
__dirname,
'./mocks/ViewNativeComponent.js'
)
},
{
find: 'react-native/Libraries/Animated/nodes/AnimatedNode',
replacement: path.resolve(__dirname, './mocks/AnimatedNode.js')
}
]
}),
Expand Down
14 changes: 12 additions & 2 deletions packages/react-strict-dom/src/native/modules/useStyleProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
*/

import type { CustomProperties, Style } from '../../types/styles';
import type { ReactNativeProps } from '../../types/renderer.native';
import type { ReactNativeStyle } from '../../types/renderer.native';
import type {
ReactNativeProps,
ReactNativeStyle,
ReactNativeStyleValue
} from '../../types/renderer.native';

import * as css from '../css';
import * as ReactNative from '../react-native';
Expand Down Expand Up @@ -76,6 +79,10 @@ function resolveUnitlessLineHeight(style: ReactNativeStyle): ReactNativeStyle {
return style;
}

function isAnimatedNode(value: ?ReactNativeStyleValue): boolean {
return value instanceof ReactNative.AnimatedNode;
}

/**
* Produces the relevant React Native props to implement the given styles, and any
* inheritable text styles that may be required.
Expand Down Expand Up @@ -208,6 +215,9 @@ export function useStyleProps(
val = inheritedValue;
}
if (val != null) {
if (isAnimatedNode(val)) {
styleProps.animated = true;
}
hasInheritableStyle = true;
inheritableStyle[key] = val;
styleProps.style[key] = val;
Expand Down
11 changes: 11 additions & 0 deletions packages/react-strict-dom/src/native/react-native/AnimatedNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/

import AnimatedNode from 'react-native/Libraries/Animated/nodes/AnimatedNode';
export { AnimatedNode };
1 change: 1 addition & 0 deletions packages/react-strict-dom/src/native/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
Text,
TextInput
} from 'react-native';
export { AnimatedNode } from './AnimatedNode';
export { LayoutConformance } from './LayoutConformance';
export { TextAncestorContext } from './TextAncestorContext';
export { ViewNativeComponent } from './ViewNativeComponent';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const animatedNodeMarker = Symbol('AnimatedNode');

export function createAnimatedNode(config) {
return Object.defineProperty({ ...config }, animatedNodeMarker, {
value: true
});
}

export default class AnimatedNode {
static [Symbol.hasInstance](value) {
return Boolean(value?.[animatedNodeMarker]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import { createAnimatedNode } from './Libraries/Animated/nodes/AnimatedNode';

export const AccessibilityInfo = {
addEventListener: jest.fn().mockReturnValue({ remove: jest.fn() }),
isReduceMotionEnabled: jest.fn().mockReturnValue(Promise.resolve(false))
Expand All @@ -19,7 +21,9 @@ export const Animated = {
Text: 'Animated.Text',
Value: jest.fn(() => {
return {
interpolate: jest.fn().mockImplementation((value) => value)
interpolate: jest
.fn()
.mockImplementation((value) => createAnimatedNode(value))
};
}),
timing: jest.fn(() => {
Expand Down
60 changes: 60 additions & 0 deletions packages/react-strict-dom/tests/html/html-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,66 @@ describe('<html.*> (native polyfills)', () => {
expect(getFontSize(secondSecond)).toBe(1.5 * 3 * 16);
});

test('inherited color from transitioned parent', () => {
const styles = css.create({
container: {
padding: '32px',
transitionProperty: 'backgroundColor, color',
transitionDuration: '300ms',
backgroundColor: {
default: 'blue',
':active': 'darkblue'
},
color: {
default: 'white',
':active': 'green'
}
},
text: {
fontSize: '24px',
color: 'inherit'
}
});

let root;
act(() => {
root = create(
<html.button style={styles.container}>
<html.span style={styles.text}>Alert Banner</html.span>
</html.button>
);
});

let button = root.toJSON();
let span = button.children[0];
expect(span.type).toBe('Text');
expect(span.props.style.color).toBe('white');

act(() => {
button.props.onPointerDown();
});

button = root.toJSON();
span = button.children[0];
expect(span.type).toBe('Animated.Text');
expect(span.props.style.color).toEqual({
inputRange: [0, 1],
outputRange: ['white', 'green']
});

act(() => {
button.props.onPointerUp();
});

button = root.toJSON();
span = button.children[0];
expect(span.type).toBe('Animated.Text');
expect(span.props.style.color).toEqual({
inputRange: [0, 1],
outputRange: ['green', 'white']
});
});

test('inherited lineHeight (unitless)', () => {
const styles = css.create({
root: {
Expand Down
Loading