-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mobile] - Remove react-native-hr
#48986
Conversation
Size Change: +18 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid change to reduce our dependencies on forked packages. 👏🏻 I left a few comments for your consideration.
@@ -5,7 +5,6 @@ export { | |||
Polygon, | |||
Rect, | |||
G, | |||
HorizontalRule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is that it makes sense to place the mobile implementation within @wordpress/primitives/src/horizontal-rule
alongside its web counterpart. What is the rationale for separating it and removing this line?
@@ -116,6 +115,8 @@ export { setClipboard, getClipboard } from './mobile/clipboard'; | |||
export { default as AudioPlayer } from './mobile/audio-player'; | |||
export { default as Badge } from './mobile/badge'; | |||
export { default as Gridicons } from './mobile/gridicons'; | |||
export { default as HR } from './mobile/hr'; | |||
export { HorizontalRule } from './mobile/hr/horizontal-rule'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This current HorizontalRule
export doesn't appear to be consumed anywhere. Should consider it private? Possibly define both components in a single file and only export one?
// primitives/src/horizontal-rule/index.native.js:
function HR () {
// ...simple line...
}
export function HorizontalRule() {
// ...line with optional text...
}
Alternatively, I wonder if it would be more appropriate to align with the web components API as much as possible, i.e. consider our "line with text" component something completely separate from a HorizontalRule
or HR
. This would allow the props and behavior of HorizontalRule
to match between web and native, possibly reducing confusion. So, we would have two files:
// primitives/src/horizontal-rule/index.native.js:
export function HorizontalRule () {
// ...simple line...
}
// components/src/mobile/labeled-horizontal-rule/index.native.js:
export function LabeledHorizontalRule() {
// ...line with optional text...
}
Lastly, the component/export name of HR
appears to be mobile-specific. Web solely relies upon HorizontalRule
. It might make sense to align with web in regards to naming and avoid HR
. WDYT?
@@ -51,6 +52,7 @@ export default function SeparatorEdit( { attributes, setAttributes } ) { | |||
{ ...useBlockProps( { | |||
className, | |||
style: hasCustomColor ? styles : undefined, | |||
...( Platform.isNative && { color: styles.color } ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that we generally discourage inline Platform
conditionals to avoid increased complexity and web bundle size. Is it possible to avoid this mobile-specific conditional by relying upon the passed style
prop and referencing style.color
or style.backgroundColor
within the HorizontalRule
implementation? I.e. attempting to align with the web API.
return ( | ||
<View style={ containerStyles }> | ||
<HRLine color={ color } lineStyle={ lineStyle } /> | ||
<HRText color={ color } text={ text } textStyle={ textStyle } /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely not necessary, but I wondered if it makes sense to rely upon the children
prop instead of a text
prop to enable component composition.
// Definition
function HorizontalRule({ children }) {
// ...
return (
<>
<HRLine />
{children}
<HRLine />
</>
);
}
// Usage
<HorizontalRule>
<Text>Read More</Text>
</HorizontalRule>;
If desired, we could take it a step further simplifying the usage by applying the required text styles via a nested component.
// Definition
function HorizontalRuleText( { children, style } ) {
const requiredStyles = { // ...required text styling... };
return (
<Text style={{...requiredStyles, ...style}} >
{children}
</Text>
);
}
HorizontalRule.Text = HorizontalRuleText;
// Usage
<HorizontalRule>
<HorizontalRule.Text>Read More</HorizontalRule.Text>
</HorizontalRule>;
color, | ||
lineStyle, | ||
marginLeft = 8, | ||
marginRight = 8, | ||
text, | ||
textStyle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to my comments regarding composition, I wonder if these custom props could be simplified and/or avoided if we relied upon composition. We could instead rely upon the de facto style
prop WDYT?
<HorizontalRule style={{ marginLeft: 16, marginRight: 16 }}>
<HorizontalRule.Text style={{ color: "green" }}>
Read More
</HorizontalRule.Text>
</HorizontalRule>;
I believe we could reduce the surface area of the component API:
HorizontalRule
:style
andchildren
HorizontalRule.Text
:style
Closing since another PR included most of these changes #51041 |
Related PRs:
react-native-hr
wordpress-mobile/gutenberg-mobile#5550What?
This PR removes the
react-native-hr
library in favor of having our own component.Why?
To reduce the usage of unnecessary libraries and also of the current forks the project uses.
How?
By implementing the
HR
mobile component that also has aHorizontalRule
wrapper.It adds a new functionality to set a
color
with this, now we'll able to support customizing the color of the Separator block.Testing Instructions
On both platforms:
Test case 1
Page break
blockMore
blockSeparator
blockTest case 2
Separator
blockTesting Instructions for Keyboard
N/A
Screenshots or screencast