-
-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to apply different border radius to RectButton component (#2792)
## Description This PR is intended to allow the use of different border radius values on the RectButton component. As mentioned in comments on #477 , it doesn’t work on Android. I tried to follow the same implementation pattern from `borderRadius`, but using `setCornerRadii` method when informed at least one prop from specific corner. Also, it is possible to merge the values from `borderRadius` or from specific corner. <!-- Description and motivation for this PR. Include 'Fixes #<number>' if this is fixing some issue. --> ## Test plan <!-- Describe how did you test this change here. --> I added a component (RectButtonBorders) on example app with some variations of values to test the changes. --------- Co-authored-by: Jakub Piasecki <[email protected]>
- Loading branch information
1 parent
74c981f
commit 6557867
Showing
3 changed files
with
165 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { RectButton } from 'react-native-gesture-handler'; | ||
|
||
export default function RectButtonBorders() { | ||
return ( | ||
<View style={styles.container}> | ||
<Button type="borderRadius" /> | ||
<Button type="borderTopLeftRadius" /> | ||
<Button type="borderTopRightRadius" /> | ||
<Button type="borderBottomLeftRadius" /> | ||
<Button type="borderBottomRightRadius" /> | ||
<RectButton | ||
style={[ | ||
styles.button, | ||
{ borderTopLeftRadius: 16, borderTopRightRadius: 16 }, | ||
]} | ||
onPress={() => alert(`Pressed borderTopRadius!`)}> | ||
<Text>border Top Radius</Text> | ||
</RectButton> | ||
<RectButton | ||
style={[ | ||
styles.button, | ||
{ borderBottomLeftRadius: 16, borderBottomRightRadius: 16 }, | ||
]} | ||
onPress={() => alert(`Pressed borderTopRadius!`)}> | ||
<Text>border Bottom Radius</Text> | ||
</RectButton> | ||
<RectButton | ||
style={[ | ||
styles.button, | ||
{ | ||
borderRadius: 8, | ||
borderTopLeftRadius: 32, | ||
borderTopRightRadius: 32, | ||
}, | ||
]} | ||
onPress={() => alert(`Pressed borderTopRadius!`)}> | ||
<Text>borderRadius and Top Radius</Text> | ||
</RectButton> | ||
<RectButton | ||
style={[ | ||
styles.button, | ||
{ | ||
borderRadius: 8, | ||
borderBottomLeftRadius: 32, | ||
borderBottomRightRadius: 32, | ||
}, | ||
]} | ||
onPress={() => alert(`Pressed borderTopRadius!`)}> | ||
<Text>borderRadius and Bottom Radius</Text> | ||
</RectButton> | ||
</View> | ||
); | ||
} | ||
|
||
type BorderTypes = | ||
| 'borderRadius' | ||
| 'borderTopLeftRadius' | ||
| 'borderTopRightRadius' | ||
| 'borderBottomLeftRadius' | ||
| 'borderBottomRightRadius'; | ||
|
||
function Button({ type }: { type: BorderTypes }) { | ||
return ( | ||
<RectButton | ||
style={[styles.button, { [type]: 16 }]} | ||
onPress={() => alert(`Pressed ${type}!`)}> | ||
<Text style={styles.text}>{type}</Text> | ||
</RectButton> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
gap: 8, | ||
flexWrap: 'wrap', | ||
justifyContent: 'center', | ||
alignContent: 'center', | ||
}, | ||
button: { | ||
width: 100, | ||
height: 100, | ||
backgroundColor: '#782aeb', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
padding: 8, | ||
}, | ||
text: { | ||
color: '#f8f9ff', | ||
}, | ||
}); |