-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 - RichText - Set a default value for selection values #40581
Conversation
Size Change: 0 B Total Size: 1.23 MB ℹ️ View Unchanged
|
c02b0c5
to
2e95aae
Compare
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.
When the font size or the line-height is changed, it forces a selection update on Aztec to show the new selected values, by setting this.needsSelectionUpdate to true.
In this case where this selection update happens it expects to have a selectionStart and selectionEnd value. On Android if these values are null or undefined it crashes.
Since this is a new case where a block can set the font size/line-height value of its Paragraph inner blocks without being focused it'll crash.
I understand that this case comes from the following condition when the component is updated, right?
I'm wondering if we should also prevent the selection update by checking that selectionStart
and selectionEnd
are defined, similar to previous conditions within shouldComponentUpdate
like:
start: this.props.selectionStart, | ||
end: this.props.selectionEnd, | ||
start: this.props.selectionStart ?? 0, | ||
end: this.props.selectionEnd ?? 0, |
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.
I noticed that this.props.selectionStart
and this.props.selectionEnd
is also used in the following lines after this block:
If we want to ensure that both props are always defined, we might consider having them as constants within the render
function, wdyt?
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.
That's a good idea! I'll update it
The thing is we do want to trigger the selection update so the new font size/line-height is updated accordingly 😅 |
Ok, I see, I thought that this might be covered by just calling |
No problem! it's a bit confusing and that itself needs its own refactor 😄 |
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.
LGTM 🎊 ! Awesome work @geriux, thanks for addressing this issue 🙇.
I followed the testing instructions and I confirm that the crash can't be reproduced.
Tested on Samsung Galaxy S20 FE 5G (Android 11) and Simulator - iPhone 13 (iOS 15.4).
…nEnd for undefined values
2e95aae
to
7fef2af
Compare
…nEnd for undefined values (#40581)
* Release script: Update react-native-editor version to 1.74.0 * Release script: Update with changes from 'npm run core preios' * Update CHANGELOG * Release script: Update react-native-editor version to 1.74.1 * Release script: Update with changes from 'npm run core preios' * Mobile - RichText - Set a default value for selectionStart / selectionEnd for undefined values (#40581) * Mobile - Update changelog Co-authored-by: Siobhan <[email protected]>
…nEnd for undefined values (#40581)
Fixes #40545
Gutenberg Mobile PR
-> Mobile - RichText - Set a default value for selection values wordpress-mobile/gutenberg-mobile#4790What?
This PR fixes an issue on Android where changing the font size/line-height of the Quote block V2 would make the app crash.
Why?
When the font size or the line-height is changed, it forces a selection update on Aztec to show the new selected values, by setting
this.needsSelectionUpdate
totrue
.In this case where this selection update happens it expects to have a
selectionStart
andselectionEnd
value. On Android if these values arenull
orundefined
it crashes.Since this is a new case where a block can set the font size/line-height value of its Paragraph inner blocks without being focused it'll crash.
How?
This PR adds a default value of
0
for cases where theselectionStart
andselectionEnd
areundefined
and a selection update was triggered.Testing Instructions
Precondition for enabling v2:
Steps:
Up (^)
arrow in the floating toolbar to go up one level and select the parent block if the inner block is focused.Screenshots or screencast