Skip to content

Commit

Permalink
Merge pull request #397 from ownego/fix/reactive-sticky-manager
Browse files Browse the repository at this point in the history
Update: modify stickyManager in AppProvider -> make it reactive
  • Loading branch information
juzser authored Aug 28, 2024
2 parents 1bc74f8 + 83b9a5f commit 5f8d23f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/components/AppProvider/AppProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const APP_FRAME_SCROLLABLE = 'AppFrameScollable';
const props = defineProps<AppProviderProps>();
defineSlots<AppProviderSlots>();
const stickyManager = new StickyManager();
const stickyManager = ref(new StickyManager());
const scrollLockManager = new ScrollLockManager();
const { isNavigationCollapsed } = useMediaQueryContext();
Expand All @@ -61,11 +61,11 @@ onMounted(() => {
if (document != null) {
if (!props.features?.dynamicTopBarAndReframe) {
stickyManager.setContainer(document);
stickyManager.value.setContainer(document);
} else {
const scrollContainerElement = document.getElementById(APP_FRAME_SCROLLABLE);
stickyManager.setContainer(scrollContainerElement || document);
stickyManager.value.setContainer(scrollContainerElement || document);
}
setBodyStyles();
Expand Down
3 changes: 1 addition & 2 deletions src/components/Scrollable/Scrollable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { scrollable } from '@polaris/components/shared';
import { debounce } from '@polaris/utilities/debounce';
import { classNames, variationName } from '@/utilities/css';
import { StickyManager } from '@/utilities/sticky-manager';
import useLazyRef from '@/use/useLazyRef';
import type { VueNode } from '@/utilities/types';
import styles from '@polaris/components/Scrollable/Scrollable.module.css';
Expand Down Expand Up @@ -87,7 +86,7 @@ const topShadow = ref<boolean>(false);
const bottomShadow = ref<boolean>(false);
const scrollArea = ref<HTMLDivElement | null>(null);
const stickyManager = useLazyRef(() => new StickyManager());
const stickyManager = ref(new StickyManager());
const finalClassName = computed(() => classNames(
styles.Scrollable,
Expand Down
16 changes: 8 additions & 8 deletions src/components/Sticky/Sticky.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ div
</template>

<script setup lang="ts">
import { type VNode, inject, ref, onMounted, onBeforeUnmount, onUpdated } from 'vue';
import { type VNode, ref, onMounted, onBeforeUnmount, onUpdated } from 'vue';
import useStickyManager from '@/use/useStickyManager';
import { getRectForNode } from '@/utilities/geometry';
import type { VueNode } from '@/utilities/types';
import type { StickyManager } from '@/utilities/sticky-manager';
export type StickyProps = {
/** Element outlining the fixed position boundaries */
Expand All @@ -29,7 +29,7 @@ const slots = defineSlots<{
}>();
const stickyManager = inject<StickyManager>('sticky-manager', {} as StickyManager);
const stickyManager = useStickyManager();
const isSticky = ref(false);
const style = ref({});
Expand All @@ -41,7 +41,7 @@ onMounted(() => {
return;
}
stickyManager.registerStickyItem({
stickyManager.value.registerStickyItem({
stickyNode: stickyNode.value,
placeHolderNode: placeHolderNode.value,
handlePositioning: handlePositioning,
Expand All @@ -56,7 +56,7 @@ onBeforeUnmount(() => {
return;
}
stickyManager.unregisterStickyItem(stickyNode.value);
stickyManager.value.unregisterStickyItem(stickyNode.value);
});
const handlePositioning = (
Expand Down Expand Up @@ -104,7 +104,7 @@ const updateComponent = () => {
if (!stickyNode.value || !placeHolderNode.value) return;
const stickyManagerItem = stickyManager.getStickyItem(stickyNode.value);
const stickyManagerItem = stickyManager.value.getStickyItem(stickyNode.value);
const didPropsChange =
!stickyManagerItem ||
boundingElement !== stickyManagerItem.boundingElement ||
Expand All @@ -113,8 +113,8 @@ const updateComponent = () => {
if (!didPropsChange) return;
stickyManager.unregisterStickyItem(stickyNode.value);
stickyManager.registerStickyItem({
stickyManager.value.unregisterStickyItem(stickyNode.value);
stickyManager.value.registerStickyItem({
stickyNode: stickyNode.value,
placeHolderNode: placeHolderNode.value,
handlePositioning: handlePositioning,
Expand Down
13 changes: 0 additions & 13 deletions src/use/useLazyRef.ts

This file was deleted.

8 changes: 6 additions & 2 deletions src/use/useStickyManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { inject } from 'vue';
import {
type Ref,
inject,
} from 'vue';
import type { StickyManager } from '@/utilities/sticky-manager';

export default function useStickyManager() {
const context = inject('sticky-manager') as StickyManager;
const context = inject('sticky-manager') as Ref<StickyManager>;

return context;
}

0 comments on commit 5f8d23f

Please sign in to comment.