Skip to content
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

Saving and restoring scroll position in composition mode #3268

Merged
merged 17 commits into from
Jun 25, 2020

Conversation

compulim
Copy link
Contributor

@compulim compulim commented Jun 22, 2020

Fixes #3252. Fixes #2859.

Changelog Entry

Added

  • Resolves #3252. Added useObserveScrollPosition and useScrollTo hooks, by @compulim in PR #3268
  • Resolves #3252. Added composition mode, which split up <ReactWebChat> into <Composer> and <BasicWebChat>, by @compulim in PR #3268

Samples

Description

New hooks to observe and restore scroll positions.

To enable hooks outside of Web Chat UI, we added a new sample to enable composition mode.

To enable composition mode, this PR will fix #2859 by enabling middleware in <Composer>.

useObserveScrollPosition

useObserveScrollPosition(observer: (ScrollObserver? | false), deps: any[]): void

type ScrollObserver = (position: ScrollPosition) => void;

type ScrollPosition {
  scrollTop: number
}

This function accept an observer function. When the scroll position has changed, the observer function will be called with the latest ScrollPosition.

The position argument can be passed to useScrollTo hook to restore scroll position.

Since the observer function will be called rapidly, please keep the code in the function as lightweight as possible.

To stop observing scroll positions, pass a falsy value to the observer argument.

If there are more than one transcripts, scrolling any of them will trigger the observer function, and there is no clear distinction of which transcript is being scrolled.

useScrollTo

useScrollTo(): (position: ScrollPosition, options: ScrollOptions) => void

type ScrollOptions {
  behavior: 'auto' | 'smooth'
}

type ScrollPosition {
  scrollTop: number
}

This function will return a function that, when called, will scroll the transcript to the specific scroll position.

If options is passed with behavior set to smooth, it will smooth-scrolling to the scroll position. Otherwise, it will jump to the scroll position instantly.

Specific Changes

  • Enable composition mode
  • Added useObserveScrollPosition and useScrollTo hooks
  • Moved to hooks API in react-scroll-to-bottom
  • Samples
    • Added "enable composition mode" sample
    • Updated 04.api/d.post-activity-event to use composition mode
    • Added save/restore scroll position sample

  • Testing Added

CHANGELOG.md Outdated Show resolved Hide resolved
docs/HOOKS.md Outdated Show resolved Hide resolved
docs/HOOKS.md Outdated Show resolved Hide resolved
docs/HOOKS.md Outdated Show resolved Hide resolved
@compulim compulim merged commit ed452fb into microsoft:master Jun 25, 2020
@compulim compulim deleted the feat-save-scroll branch June 25, 2020 19:04
@compulim compulim mentioned this pull request Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OC: Set/get scroll bar position (Jun 15) Code: Move createXXXRenderer into <Composer>
2 participants