-
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
[RNMobile] Auto-scroll upon block insertion #57273
Merged
fluiddot
merged 15 commits into
trunk
from
rnmobile/fix/auto-scroll-upon-block-insertion
Jan 2, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6ee8c01
Add `useScrollToSection` hook
fluiddot 6d148b7
Add `useScrollToElement` hook
fluiddot b6d7c69
Update logic to retrieve `KeyboardAwareFlatList` ref using `forwardRef`
fluiddot 5f9e1c8
Replace `useScrollToTextInput` with `useScrollToSection`
fluiddot d9cbde9
Expose `scrollToSection` and `scrollToElement` in Android implementat…
fluiddot bbe30e3
Add `useScrollUponInsertion` hook
fluiddot 92750f2
Add `useScroll` hook to abstract common logic in `KeyboardAwareFlatList`
fluiddot 2888ff6
Calculate `nativeScrollRef` based on platform in `useScroll` hook
fluiddot 51c232b
Update unit test to adapt `useScrollToSection` hook
fluiddot f891690
Remove `nativeScrollRef` in favor of calculating the ref in `Keyboard…
fluiddot 84beb25
Add unit test for `useScroll` hook
fluiddot e49f5c3
Ensure layout event of `BlockListItemCell` is triggered in tests
fluiddot 87a7a12
Avoid triggering auto-scroll for the same client ID
fluiddot c73ee74
Merge branch 'trunk' into rnmobile/fix/auto-scroll-upon-block-insertion
fluiddot 8827a4e
Update `react-native-editor` changelog
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
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
52 changes: 52 additions & 0 deletions
52
packages/block-editor/src/components/block-list/use-scroll-upon-insertion.native.js
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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useBlockListContext } from './block-list-context'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
const useScrollUponInsertion = ( { | ||
clientId, | ||
isSelected, | ||
isLayoutCalculated, | ||
elementRef, | ||
} ) => { | ||
const { scrollRef } = useBlockListContext(); | ||
const wasBlockJustInserted = useSelect( | ||
( select ) => | ||
!! select( blockEditorStore ).wasBlockJustInserted( | ||
clientId, | ||
'inserter_menu' | ||
), | ||
[ clientId ] | ||
); | ||
useEffect( () => { | ||
const lastScrollTo = scrollRef?.lastScrollTo.current; | ||
const alreadyScrolledTo = lastScrollTo?.clientId === clientId; | ||
if ( | ||
alreadyScrolledTo || | ||
! isSelected || | ||
! scrollRef || | ||
! wasBlockJustInserted || | ||
! isLayoutCalculated | ||
) { | ||
return; | ||
} | ||
scrollRef.scrollToElement( elementRef ); | ||
lastScrollTo.clientId = clientId; | ||
}, [ | ||
isSelected, | ||
scrollRef, | ||
wasBlockJustInserted, | ||
elementRef, | ||
isLayoutCalculated, | ||
clientId, | ||
] ); | ||
}; | ||
|
||
export default useScrollUponInsertion; |
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
Oops, something went wrong.
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.
Love this! 😍