Skip to content

Commit

Permalink
fix: RichText applies direction-specific padding
Browse files Browse the repository at this point in the history
Certain contexts apply different padding for different directions, e.g.
horizontal vs vertical, left vs right.
  • Loading branch information
dcalhoun committed Aug 4, 2023
1 parent 37d3fa3 commit 6205651
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ exports[`Audio block renders audio block error state without crashing 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -355,6 +356,7 @@ exports[`Audio block renders audio file without crashing 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ exports[`File block renders file error state without crashing 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -174,7 +175,10 @@ exports[`File block renders file error state without crashing 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -311,6 +315,7 @@ exports[`File block renders file without crashing 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -399,7 +404,10 @@ exports[`File block renders file without crashing 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ exports[`Paragraph block should render without crashing and match snapshot 1`] =
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ exports[`Preformatted should match snapshot when content is empty 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -60,7 +63,10 @@ exports[`Preformatted should match snapshot when content is not empty 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`Search Block renders block with button inside option 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -139,7 +140,10 @@ exports[`Search Block renders block with button inside option 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -229,6 +233,7 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -423,7 +428,10 @@ exports[`Search Block renders block with label hidden matches snapshot 1`] = `
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -513,6 +521,7 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
style={
[
undefined,
{},
undefined,
]
}
Expand Down Expand Up @@ -637,7 +646,10 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -727,6 +739,7 @@ exports[`Search Block renders with no-button option matches snapshot 1`] = `
style={
[
undefined,
{},
undefined,
]
}
Expand Down
15 changes: 10 additions & 5 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,17 @@ export class RichText extends Component {
maxWidth && this.state.width && maxWidth - this.state.width < 10
? maxWidth
: this.state.width;

const paddingStyles = {};
for ( const key in style ) {
if ( /padding/.test( key ) ) {
paddingStyles[ key ] = style[ key ];
}
}

const containerStyles = [
style?.padding &&
style?.backgroundColor && {
padding: style.padding,
backgroundColor: style.backgroundColor,
},
style && { backgroundColor: style.backgroundColor },
paddingStyles,
containerWidth && {
width: containerWidth,
},
Expand Down
10 changes: 8 additions & 2 deletions packages/rich-text/src/test/__snapshots__/index.native.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ exports[`<RichText/> Font Size should update the font size when style prop with
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down Expand Up @@ -46,7 +49,10 @@ exports[`<RichText/> Font Size should update the font size with decimals when st
<View
style={
[
undefined,
{
"backgroundColor": undefined,
},
{},
undefined,
]
}
Expand Down

0 comments on commit 6205651

Please sign in to comment.