-
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
[RNMobile] Fix drag mode not being enabled when long-pressing over Shortcode block #41155
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34743a8
Add prop for disabling suggestions button
fluiddot 0d38829
Use allowed formats in format types calculation
fluiddot 6c90982
Add RichText version to PlainText component
fluiddot 9df81c0
Use experimental version of PlainText in Shortcode block
fluiddot d2b2e6a
Add disableAutocorrection prop to RichText
fluiddot 9b98382
Disable autocorrection in Shortcode block
fluiddot 630f5c9
Update PlainText props in Shortcode block
fluiddot 4b9a25c
Use pre as tagName in PlainText
fluiddot 77ddf1a
Rename replaceLineBreaks function
fluiddot 81af835
Update shortcode block unit tests
fluiddot 76e58ed
Prevent text input focus when selecting Shortcode block
fluiddot af35786
Force text color in Shortcode block
fluiddot 0433a92
Remove tagName prop from PlainText component
fluiddot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
9 changes: 9 additions & 0 deletions
9
packages/block-library/src/shortcode/test/__snapshots__/edit.native.js.snap
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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Shortcode block edits content 1`] = ` | ||
"<!-- wp:shortcode --> | ||
[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg] | ||
<!-- /wp:shortcode -->" | ||
`; | ||
|
||
exports[`Shortcode block inserts block 1`] = `"<!-- wp:shortcode /-->"`; |
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 |
---|---|---|
@@ -1,58 +1,76 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import renderer from 'react-test-renderer'; | ||
import { TextInput } from 'react-native'; | ||
import { | ||
getEditorHtml, | ||
initializeEditor, | ||
fireEvent, | ||
waitFor, | ||
} from 'test/helpers'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockEdit } from '@wordpress/block-editor'; | ||
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks'; | ||
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; | ||
import { registerCoreBlocks } from '@wordpress/block-library'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { metadata, settings, name } from '../index'; | ||
beforeAll( () => { | ||
// Register all core blocks | ||
registerCoreBlocks(); | ||
} ); | ||
|
||
afterAll( () => { | ||
// Clean up registered blocks | ||
getBlockTypes().forEach( ( block ) => { | ||
unregisterBlockType( block.name ); | ||
} ); | ||
} ); | ||
|
||
describe( 'Shortcode block', () => { | ||
it( 'inserts block', async () => { | ||
const { | ||
getByA11yLabel, | ||
getByTestId, | ||
getByText, | ||
} = await initializeEditor(); | ||
|
||
const Shortcode = ( { clientId, ...props } ) => ( | ||
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } /> | ||
); | ||
fireEvent.press( getByA11yLabel( 'Add block' ) ); | ||
|
||
describe( 'Shortcode', () => { | ||
beforeAll( () => { | ||
registerBlockType( name, { | ||
...metadata, | ||
...settings, | ||
const blockList = getByTestId( 'InserterUI-Blocks' ); | ||
// onScroll event used to force the FlatList to render all items | ||
fireEvent.scroll( blockList, { | ||
nativeEvent: { | ||
contentOffset: { y: 0, x: 0 }, | ||
contentSize: { width: 100, height: 100 }, | ||
layoutMeasurement: { width: 100, height: 100 }, | ||
}, | ||
} ); | ||
} ); | ||
|
||
afterAll( () => { | ||
unregisterBlockType( name ); | ||
} ); | ||
fireEvent.press( await waitFor( () => getByText( 'Shortcode' ) ) ); | ||
|
||
it( 'renders without crashing', () => { | ||
const component = renderer.create( | ||
<Shortcode attributes={ { text: '' } } /> | ||
); | ||
const rendered = component.toJSON(); | ||
expect( rendered ).toBeTruthy(); | ||
expect( getByA11yLabel( /Shortcode Block\. Row 1/ ) ).toBeVisible(); | ||
expect( getEditorHtml() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'renders given text without crashing', () => { | ||
const component = renderer.create( | ||
<Shortcode | ||
attributes={ { | ||
text: | ||
'[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]', | ||
} } | ||
/> | ||
); | ||
const testInstance = component.root; | ||
const textInput = testInstance.findByType( TextInput ); | ||
expect( textInput ).toBeTruthy(); | ||
expect( textInput.props.value ).toBe( | ||
'[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]' | ||
it( 'edits content', async () => { | ||
const { getByA11yLabel, getByPlaceholderText } = await initializeEditor( | ||
{ | ||
initialHtml: '<!-- wp:shortcode /-->', | ||
} | ||
); | ||
const shortcodeBlock = getByA11yLabel( /Shortcode Block\. Row 1/ ); | ||
fireEvent.press( shortcodeBlock ); | ||
|
||
const textField = getByPlaceholderText( 'Add a shortcode…' ); | ||
fireEvent( textField, 'focus' ); | ||
fireEvent( textField, 'onChange', { | ||
nativeEvent: { | ||
eventCount: 1, | ||
target: undefined, | ||
text: '[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]', | ||
}, | ||
} ); | ||
|
||
expect( getEditorHtml() ).toMatchSnapshot(); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this should come from props, currently, it's fine because only the
Shortcode
block uses it but if we want to use it in other blocks, thetagName
would be different, what do you think?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.
Yep, good point. In fact, I think that we could even remove the prop to use the default value
div
(reference). As far as I checked, it works even better than usingpre
tag 😅 .ios-shortcode-block.mp4
android-shortcode-block.mp4
As an additional note, I'd like to share that during implementation, I tried using different tag names like
p
orspan
but found some issues:p
: On Android, it doesn't allow to add new lines at the end of the content.gutenberg/packages/rich-text/src/component/index.native.js
Lines 1095 to 1097 in 51db4bf
span
: Automatically wraps thespan
tags withp
tags. Besides, adding new lines leads to odd issues where lines are merged or add extra newlines 🙃.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.
Sounds good! At first I was wondering how it was showing the monospace font without the
pre
tag but I checked we are setting the font from the styles so we are good 👍