Skip to content

Commit 7a6fb7c

Browse files
authored
[Scrollable] refactor: rewrite Scrollable utilizing platform features (#7443)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? This updates the Scrollable component to be a function component, but also changes the fundamental implementation strategy. It no longer controls the DOM node's scroll, allowing the platform to handle all scrolling interaction and only using native features to supply enhancements for the `ScrollTo` component and the scroll `hint` functionality. Primary Benefits: - It allows for smooth scrolling in React 18 on iOS. Since we are no longer setting scroll position on the target element as a side effect of state, it has no conflict with automatic batching by React. See #7424 - There are minimal wasted renders when scrolling. Previously, we would render many times just by virtue of scrolling. resolves #7424 ### WHAT is this pull request doing? <details> <summary>Before/After 👀</summary> #### Before ![](https://screenshot.click/19-54-tmbl7-1k4ao.png) Momentum scrolling interrupted by render/commit cycles https://user-images.githubusercontent.com/8847861/196776562-0517c364-9992-4415-973d-6d77843a4f0b.mov #### After ![](https://screenshot.click/19-04-seyci-ivgq1.png) Smooth scrolling https://user-images.githubusercontent.com/8847861/196776608-5464f140-ee9b-437b-9229-6a80f4cb7a87.mov </details> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) Access storybook on an iOS device: ![](https://screenshot.click/19-38-t6tq5-tgs56.png) Using iOS device, navigate to the `Scrollable` component: `http://<your.network.ip>:6006/?path=/story/all-components-scrollable--default&globals=profiler:true` - [ ] On `main` branch: scrolling should be janky - experience is choppy, momentum gets interrupted - [ ] On this branch: scrolling should be smooth - [ ] `shadow` prop works as intended - [ ] `hint` prop works as intended - [ ] `ScrollTo` component works within `Scrollable` ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent db951f8 commit 7a6fb7c

File tree

4 files changed

+266
-213
lines changed

4 files changed

+266
-213
lines changed

.changeset/many-otters-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Improve performance of the Scrollable component with React 18

polaris-react/src/components/Scrollable/Scrollable.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
overflow-y: auto;
2828
}
2929

30-
.verticalHasScrolling {
31-
overflow-y: scroll;
32-
}
33-
3430
.hasTopShadow {
3531
box-shadow: var(--pc-scrollable-shadow-top);
3632
}

polaris-react/src/components/Scrollable/Scrollable.stories.tsx

Lines changed: 148 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,37 @@ export default {
99
export function Default() {
1010
return (
1111
<Card title="Terms of service" sectioned>
12-
<Scrollable shadow style={{height: '100px'}} focusable>
12+
<Scrollable shadow style={{height: '200px'}} focusable>
13+
<p>
14+
By signing up for the Shopify service (“Service”) or any of the
15+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
16+
the following terms and conditions (“Terms of Service”). The Services
17+
offered by Shopify under the Terms of Service include various products
18+
and services to help you create and manage a retail store, whether an
19+
online store (“Online Services”), a physical retail store (“POS
20+
Services”), or both. Any new features or tools which are added to the
21+
current Service shall be also subject to the Terms of Service. You can
22+
review the current version of the Terms of Service at any time at
23+
https://www.shopify.com/legal/terms. Shopify reserves the right to
24+
update and change the Terms of Service by posting updates and changes
25+
to the Shopify website. You are advised to check the Terms of Service
26+
from time to time for any updates or changes that may impact you.
27+
</p>
28+
<p>
29+
By signing up for the Shopify service (“Service”) or any of the
30+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
31+
the following terms and conditions (“Terms of Service”). The Services
32+
offered by Shopify under the Terms of Service include various products
33+
and services to help you create and manage a retail store, whether an
34+
online store (“Online Services”), a physical retail store (“POS
35+
Services”), or both. Any new features or tools which are added to the
36+
current Service shall be also subject to the Terms of Service. You can
37+
review the current version of the Terms of Service at any time at
38+
https://www.shopify.com/legal/terms. Shopify reserves the right to
39+
update and change the Terms of Service by posting updates and changes
40+
to the Shopify website. You are advised to check the Terms of Service
41+
from time to time for any updates or changes that may impact you.
42+
</p>
1343
<p>
1444
By signing up for the Shopify service (“Service”) or any of the
1545
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
@@ -124,10 +154,10 @@ export function WithHorizonalScrollPrevention() {
124154
);
125155
}
126156

127-
export function ToChildComponent() {
157+
export function ScrollToChildComponent() {
128158
return (
129159
<Card title="Terms of service" sectioned>
130-
<Scrollable shadow style={{height: '100px'}}>
160+
<Scrollable shadow style={{height: '200px'}}>
131161
<ol>
132162
<li>Account Terms</li>
133163
</ol>
@@ -176,9 +206,9 @@ export function ToChildComponent() {
176206
<ol>
177207
<li>Account Activation</li>
178208
</ol>
179-
<Scrollable.ScrollTo>
180-
<p>2.1 Shopify Account</p>
181-
</Scrollable.ScrollTo>
209+
210+
<Scrollable.ScrollTo />
211+
<strong>2.1 Shopify Account</strong>
182212

183213
<p>
184214
Subject to section 2.1.2, the person signing up for the Service will
@@ -416,3 +446,115 @@ export function ToChildComponent() {
416446
</Card>
417447
);
418448
}
449+
450+
export function WithScrollHint() {
451+
return (
452+
<Card title="Terms of service" sectioned>
453+
<Scrollable hint shadow style={{height: '200px'}} focusable>
454+
<p>
455+
By signing up for the Shopify service (“Service”) or any of the
456+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
457+
the following terms and conditions (“Terms of Service”). The Services
458+
offered by Shopify under the Terms of Service include various products
459+
and services to help you create and manage a retail store, whether an
460+
online store (“Online Services”), a physical retail store (“POS
461+
Services”), or both. Any new features or tools which are added to the
462+
current Service shall be also subject to the Terms of Service. You can
463+
review the current version of the Terms of Service at any time at
464+
https://www.shopify.com/legal/terms. Shopify reserves the right to
465+
update and change the Terms of Service by posting updates and changes
466+
to the Shopify website. You are advised to check the Terms of Service
467+
from time to time for any updates or changes that may impact you.
468+
</p>
469+
<p>
470+
By signing up for the Shopify service (“Service”) or any of the
471+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
472+
the following terms and conditions (“Terms of Service”). The Services
473+
offered by Shopify under the Terms of Service include various products
474+
and services to help you create and manage a retail store, whether an
475+
online store (“Online Services”), a physical retail store (“POS
476+
Services”), or both. Any new features or tools which are added to the
477+
current Service shall be also subject to the Terms of Service. You can
478+
review the current version of the Terms of Service at any time at
479+
https://www.shopify.com/legal/terms. Shopify reserves the right to
480+
update and change the Terms of Service by posting updates and changes
481+
to the Shopify website. You are advised to check the Terms of Service
482+
from time to time for any updates or changes that may impact you.
483+
</p>
484+
<p>
485+
By signing up for the Shopify service (“Service”) or any of the
486+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
487+
the following terms and conditions (“Terms of Service”). The Services
488+
offered by Shopify under the Terms of Service include various products
489+
and services to help you create and manage a retail store, whether an
490+
online store (“Online Services”), a physical retail store (“POS
491+
Services”), or both. Any new features or tools which are added to the
492+
current Service shall be also subject to the Terms of Service. You can
493+
review the current version of the Terms of Service at any time at
494+
https://www.shopify.com/legal/terms. Shopify reserves the right to
495+
update and change the Terms of Service by posting updates and changes
496+
to the Shopify website. You are advised to check the Terms of Service
497+
from time to time for any updates or changes that may impact you.
498+
</p>
499+
</Scrollable>
500+
</Card>
501+
);
502+
}
503+
504+
export function OnScrolledToBottom() {
505+
return (
506+
<Card title="Terms of service" sectioned>
507+
<Scrollable
508+
focusable
509+
style={{height: '200px'}}
510+
onScrolledToBottom={() => console.log('scrolled to bottom')}
511+
>
512+
<p>
513+
By signing up for the Shopify service (“Service”) or any of the
514+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
515+
the following terms and conditions (“Terms of Service”). The Services
516+
offered by Shopify under the Terms of Service include various products
517+
and services to help you create and manage a retail store, whether an
518+
online store (“Online Services”), a physical retail store (“POS
519+
Services”), or both. Any new features or tools which are added to the
520+
current Service shall be also subject to the Terms of Service. You can
521+
review the current version of the Terms of Service at any time at
522+
https://www.shopify.com/legal/terms. Shopify reserves the right to
523+
update and change the Terms of Service by posting updates and changes
524+
to the Shopify website. You are advised to check the Terms of Service
525+
from time to time for any updates or changes that may impact you.
526+
</p>
527+
<p>
528+
By signing up for the Shopify service (“Service”) or any of the
529+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
530+
the following terms and conditions (“Terms of Service”). The Services
531+
offered by Shopify under the Terms of Service include various products
532+
and services to help you create and manage a retail store, whether an
533+
online store (“Online Services”), a physical retail store (“POS
534+
Services”), or both. Any new features or tools which are added to the
535+
current Service shall be also subject to the Terms of Service. You can
536+
review the current version of the Terms of Service at any time at
537+
https://www.shopify.com/legal/terms. Shopify reserves the right to
538+
update and change the Terms of Service by posting updates and changes
539+
to the Shopify website. You are advised to check the Terms of Service
540+
from time to time for any updates or changes that may impact you.
541+
</p>
542+
<p>
543+
By signing up for the Shopify service (“Service”) or any of the
544+
services of Shopify Inc. (“Shopify”) you are agreeing to be bound by
545+
the following terms and conditions (“Terms of Service”). The Services
546+
offered by Shopify under the Terms of Service include various products
547+
and services to help you create and manage a retail store, whether an
548+
online store (“Online Services”), a physical retail store (“POS
549+
Services”), or both. Any new features or tools which are added to the
550+
current Service shall be also subject to the Terms of Service. You can
551+
review the current version of the Terms of Service at any time at
552+
https://www.shopify.com/legal/terms. Shopify reserves the right to
553+
update and change the Terms of Service by posting updates and changes
554+
to the Shopify website. You are advised to check the Terms of Service
555+
from time to time for any updates or changes that may impact you.
556+
</p>
557+
</Scrollable>
558+
</Card>
559+
);
560+
}

0 commit comments

Comments
 (0)