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
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,9 @@ static void RCTAddContourEffectToLayer(
UIEdgeInsets imageCapInsets = image.capInsets;
CGRect contentsCenter = CGRect{
CGPoint{imageCapInsets.left / imageSize.width, imageCapInsets.top / imageSize.height},
CGSize{(CGFloat)1.0 / imageSize.width, (CGFloat)1.0 / imageSize.height}};
CGSize{
MAX(0, (imageSize.width - imageCapInsets.left - imageCapInsets.right) / imageSize.width),
MAX(0, (imageSize.height - imageCapInsets.top - imageCapInsets.bottom) / imageSize.height)}};
layer.contents = (id)image.CGImage;
layer.contentsScale = image.scale;

Expand Down
8 changes: 2 additions & 6 deletions packages/react-native/React/Views/RCTBorderDrawing.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,8 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn

const CGSize size = makeStretchable ? (CGSize){
// 1pt for the middle stretchable area along each axis
// we also need to round the edge insets to avoid border bleeding
// this is because if the size is decimal, when calculating the unit
// rectangle for CALayer.contentsCenter we encounter rounding errors
// which causes visual glitches
ceil(edgeInsets.left) + 1 + ceil(edgeInsets.right),
ceil(edgeInsets.top) + 1 + ceil(edgeInsets.bottom),
edgeInsets.left + 1 + edgeInsets.right,
edgeInsets.top + 1 + edgeInsets.bottom,
} : viewSize;

UIGraphicsImageRenderer *const imageRenderer =
Expand Down
5 changes: 4 additions & 1 deletion packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ - (void)displayLayer:(CALayer *)layer
CGSize size = image.size;
UIEdgeInsets insets = image.capInsets;
CGRectMake(
insets.left / size.width, insets.top / size.height, (CGFloat)1.0 / size.width, (CGFloat)1.0 / size.height);
insets.left / size.width,
insets.top / size.height,
MAX(0, (size.width - insets.left - insets.right) / size.width),
MAX(0, (size.height - insets.top - insets.bottom) / size.height));
});

layer.contents = (id)image.CGImage;
Expand Down
131 changes: 131 additions & 0 deletions packages/rn-tester/js/examples/Border/BorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import type {RNTesterModule} from '../../types/RNTesterTypes';

import hotdog from '../../assets/hotdog.jpg';
import RNTesterText from '../../components/RNTesterText';
import * as React from 'react';
import {
DynamicColorIOS,
Expand Down Expand Up @@ -257,6 +258,33 @@ const styles = StyleSheet.create({
top: -10,
backgroundColor: 'blue',
},
hairlineBox: {
width: 44,
height: 44,
borderWidth: StyleSheet.hairlineWidth,
borderColor: 'black',
backgroundColor: '#f5f5f5',
},
hairlineBoxContainer: {
alignItems: 'center',
marginRight: 8,
},
hairlineRow: {
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: 'black',
justifyContent: 'center',
paddingHorizontal: 4,
},
subpixelLabel: {
fontSize: 9,
marginTop: 4,
},
sectionTitle: {
fontSize: 11,
fontWeight: 'bold',
marginBottom: 6,
marginTop: 10,
},
});

export default {
Expand Down Expand Up @@ -622,5 +650,108 @@ export default {
);
},
},
{
title: 'Hairline borders at subpixel Y offsets',
name: 'hairline-subpixel-y-offsets',
description:
'Ensure hairlineWidth borders render completely on all sides even when positioned at fractional/subpixel Y offsets on iOS',
render: function (): React.Node {
const subpixelYOffsets = [0, 0.25, 0.33, 0.5, 0.67, 0.75];
return (
<View testID="border-test-hairline-subpixel-y-offsets">
<RNTesterText style={styles.sectionTitle}>
Boxes at fractional Y offsets (borderWidth = hairlineWidth):
</RNTesterText>
<View style={styles.wrapper}>
{subpixelYOffsets.map(yOffset => (
<View key={yOffset} style={styles.hairlineBoxContainer}>
<View style={[styles.hairlineBox, {top: yOffset}]} />
<RNTesterText style={styles.subpixelLabel}>
{`+${yOffset}pt`}
</RNTesterText>
</View>
))}
</View>

<RNTesterText style={styles.sectionTitle}>
Stacked rows with hairline bottom borders (fractional heights):
</RNTesterText>
<View>
{subpixelYOffsets.map((fraction, index) => (
<View
key={index}
style={[styles.hairlineRow, {height: 24 + fraction}]}>
<RNTesterText style={styles.subpixelLabel}>
{`Row ${index + 1} (height: ${(24 + fraction).toFixed(2)}pt)`}
</RNTesterText>
</View>
))}
</View>

<RNTesterText style={styles.sectionTitle}>
Single-side hairline borders at fractional Y offset (+0.33pt):
</RNTesterText>
<View style={styles.wrapper}>
<View style={styles.hairlineBoxContainer}>
<View
style={[
styles.hairlineBox,
{
borderWidth: 0,
borderTopWidth: StyleSheet.hairlineWidth,
borderColor: 'red',
top: 0.33,
},
]}
/>
<RNTesterText style={styles.subpixelLabel}>top</RNTesterText>
</View>
<View style={styles.hairlineBoxContainer}>
<View
style={[
styles.hairlineBox,
{
borderWidth: 0,
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: 'red',
top: 0.33,
},
]}
/>
<RNTesterText style={styles.subpixelLabel}>bottom</RNTesterText>
</View>
<View style={styles.hairlineBoxContainer}>
<View
style={[
styles.hairlineBox,
{
borderWidth: 0,
borderLeftWidth: StyleSheet.hairlineWidth,
borderColor: 'red',
top: 0.33,
},
]}
/>
<RNTesterText style={styles.subpixelLabel}>left</RNTesterText>
</View>
<View style={styles.hairlineBoxContainer}>
<View
style={[
styles.hairlineBox,
{
borderWidth: 0,
borderRightWidth: StyleSheet.hairlineWidth,
borderColor: 'red',
top: 0.33,
},
]}
/>
<RNTesterText style={styles.subpixelLabel}>right</RNTesterText>
</View>
</View>
</View>
);
},
},
],
} as RNTesterModule;