Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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
* @format
*/

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

import type {HostInstance, ViewStyle} from 'react-native';

import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';
import {StyleSheet, View} from 'react-native';

// Lays out a container with `style` around a 10x10 child, and returns where
// the child sits in the container and how tall the container is.
function layOut(style: ViewStyle): {
childTop: number,
childLeft: number,
containerHeight: number,
} {
const root = Fantom.createRoot();
const containerRef = createRef<HostInstance>();
const childRef = createRef<HostInstance>();

Fantom.runTask(() => {
root.render(
<View
collapsable={false}
ref={containerRef}
style={[styles.container, style]}>
<View collapsable={false} ref={childRef} style={styles.child} />
</View>,
);
});

const container = nullthrows(containerRef.current).getBoundingClientRect();
const child = nullthrows(childRef.current).getBoundingClientRect();
root.destroy();

return {
childTop: child.y - container.y,
childLeft: child.x - container.x,
containerHeight: container.height,
};
}

const styles = StyleSheet.create({
container: {alignSelf: 'flex-start'},
child: {width: 10, height: 10},
});

test('block-axis padding longhands take precedence over the physical edges', () => {
expect(
layOut({
paddingTop: 0,
paddingBlockStart: 8,
paddingBottom: 0,
paddingBlockEnd: 4,
}),
).toEqual({childTop: 8, childLeft: 0, containerHeight: 22});
});

test('inline-axis padding longhands take precedence over the physical edges', () => {
expect(layOut({paddingLeft: 0, paddingInlineStart: 8}).childLeft).toBe(8);
});

test('the physical edges apply when no longhand is set', () => {
expect(layOut({paddingTop: 6, paddingBottom: 3})).toEqual({
childTop: 6,
childLeft: 0,
containerHeight: 19,
});
});

test('the physical edges take precedence over the paddingBlock shorthand', () => {
expect(layOut({paddingTop: 2, paddingBlock: 8}).childTop).toBe(2);
});
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ void YogaLayoutableShadowNode::updateYogaProps() {
if (props.paddingBlock.isDefined()) {
result.setPadding(yoga::Edge::Vertical, props.paddingBlock);
}
// Yoga has no block-start or block-end edge. Setting the physical edges
// makes these win over `paddingTop` and `paddingBottom`, as Yoga's `Start`
// and `End` win over `Left` and `Right`.
if (props.paddingBlockStart.isDefined()) {
result.setPadding(yoga::Edge::Top, props.paddingBlockStart);
}
if (props.paddingBlockEnd.isDefined()) {
result.setPadding(yoga::Edge::Bottom, props.paddingBlockEnd);
}
if (props.borderBlockWidth.isDefined()) {
result.setBorder(yoga::Edge::Vertical, props.borderBlockWidth);
}
Expand All @@ -527,12 +536,6 @@ void YogaLayoutableShadowNode::updateYogaProps() {
if (result.margin(yoga::Edge::Bottom).isUndefined()) {
result.setMargin(yoga::Edge::Bottom, props.marginBlockEnd);
}
if (result.padding(yoga::Edge::Top).isUndefined()) {
result.setPadding(yoga::Edge::Top, props.paddingBlockStart);
}
if (result.padding(yoga::Edge::Bottom).isUndefined()) {
result.setPadding(yoga::Edge::Bottom, props.paddingBlockEnd);
}
if (result.border(yoga::Edge::Top).isUndefined()) {
result.setBorder(yoga::Edge::Top, props.borderBlockStartWidth);
}
Expand Down
Loading