Skip to content

Saving and restoring scroll position in composition mode#3268

Merged
compulim merged 17 commits intomicrosoft:masterfrom
compulim:feat-save-scroll
Jun 25, 2020
Merged

Saving and restoring scroll position in composition mode#3268
compulim merged 17 commits intomicrosoft:masterfrom
compulim:feat-save-scroll

Conversation

@compulim
Copy link
Copy Markdown
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

Comment thread CHANGELOG.md Outdated
Comment thread docs/HOOKS.md Outdated
Comment thread docs/HOOKS.md Outdated
Comment thread docs/HOOKS.md Outdated
Comment thread packages/component/src/BasicTranscript.js Outdated
Comment thread packages/component/src/BasicTranscript.js
Comment thread samples/04.api/d.post-activity-event/index.html Outdated
Comment thread samples/04.api/n.save-restore-scroll-position/README.md Outdated
@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