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
Expand Up @@ -306,6 +306,7 @@ internal class BorderDrawable(
* after drawing is done, we will re-enable it.
*/
borderPaint.isAntiAlias = false
borderPaint.style = Paint.Style.FILL
val width = bounds.width()
val height = bounds.height()
if (borderLeft > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ class BorderDrawableTest {
assertThat(drawBorderPaint(drawable).pathEffect).isNull()
}

@Test
fun unevenBorderColorsAreFilledAfterAUniformBorderColorWasDrawn() {
val drawable = createDrawable()
// A uniform color is drawn as a stroke.
assertThat(drawBorderPaint(drawable).style).isEqualTo(Paint.Style.STROKE)

drawable.setBorderColor(LogicalEdge.LEFT, Color.BLUE)

// Uneven colors are drawn as filled quadrilaterals.
assertThat(drawBorderPaint(drawable).style).isEqualTo(Paint.Style.FILL)
}

private fun createDrawable(): BorderDrawable {
val borderInsets = BorderInsets().apply { setBorderWidth(LogicalEdge.ALL, 8f) }
return BorderDrawable(
context = RuntimeEnvironment.getApplication(),
borderWidth = Spacing(0f),
borderRadius = null,
borderInsets = borderInsets,
borderStyle = null,
)
.apply {
setBounds(0, 0, 240, 120)
setBorderWidth(Spacing.ALL, 8f)
setBorderColor(LogicalEdge.ALL, Color.RED)
}
}

private fun drawBorderPaint(drawable: BorderDrawable): Paint {
val canvas = mock<Canvas>()
drawable.draw(canvas)
Expand Down
36 changes: 36 additions & 0 deletions packages/rn-tester/js/examples/Border/BorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,43 @@
import type {RNTesterModule} from '../../types/RNTesterTypes';

import hotdog from '../../assets/hotdog.jpg';
import RNTesterText from '../../components/RNTesterText';
import * as React from 'react';
import {useState} from 'react';
import {
DynamicColorIOS,
Image,
Platform,
PlatformColor,
Pressable,
StyleSheet,
View,
} from 'react-native';

function BorderColorChangeExample(): React.Node {
const [perSide, setPerSide] = useState(false);
return (
<Pressable
testID="border-color-change-button"
onPress={() => setPerSide(value => !value)}>
<RNTesterText>
{perSide ? 'Per-side colors' : 'One color'} (tap to change)
</RNTesterText>
<View
testID="border-test-color-change"
style={{alignSelf: 'flex-start', padding: 10}}>
<View
style={[
styles.box,
{borderWidth: 10},
perSide ? styles.border2 : {borderColor: 'black'},
]}
/>
</View>
</Pressable>
);
}

const styles = StyleSheet.create({
box: {
width: 100,
Expand Down Expand Up @@ -600,6 +627,15 @@ export default {
);
},
},
{
title: 'Changing to per-side colors',
name: 'color-change',
description:
'A border that changes from one color to per-side colors stays inside the view',
render: function (): React.Node {
return <BorderColorChangeExample />;
},
},
{
title: 'Borders and scaling transforms',
name: 'scaling-transforms',
Expand Down
20 changes: 20 additions & 0 deletions packages/rn-tester/visual-tests/flows/border.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ appId: ${APP_ID}
path: ${VISUAL_OUTPUT_DIR}/border/equal-width-borders/default
cropOn:
id: 'border-test-equal-width-borders'
- runFlow:
file: ../helpers/open-example.yml
env:
EXAMPLE_URL: rntester://example/BorderExample/color-change
- extendedWaitUntil:
visible:
id: 'border-test-color-change'
timeout: 15000
- tapOn:
id: 'border-color-change-button'
- extendedWaitUntil:
visible:
text: 'Per-side colors.*'
timeout: 15000
- waitForAnimationToEnd:
timeout: 5000
- takeScreenshot:
path: ${VISUAL_OUTPUT_DIR}/border/color-change/per-side-colors
cropOn:
id: 'border-test-color-change'
1 change: 1 addition & 0 deletions packages/rn-tester/visual-tests/suites/border.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
| `corner-radii` | Initial rendering |
| `child-clipping-radius` | Initial rendering |
| `equal-width-borders` | Initial rendering |
| `color-change` | After tapping to change from one border color to per-side colors |

Screenshots use the existing RNTester example crops. Each example starts from a fresh app launch; captures wait for the target and for animations to settle.
Loading