-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1f988b
commit 14f4e53
Showing
13 changed files
with
306 additions
and
298 deletions.
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
41 changes: 22 additions & 19 deletions
41
src/composables/use-has-scroll-past-threshold.composable.ts
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 |
---|---|---|
@@ -1,34 +1,37 @@ | ||
import type { Ref } from 'vue'; | ||
import { useState } from '@empathyco/x-components'; | ||
import { computed, ref, watch } from 'vue'; | ||
import type { ScrollComponentState } from '@empathyco/x-components/types' | ||
import type { Ref } from 'vue' | ||
import { useState } from '@empathyco/x-components' | ||
import { computed, ref, watch } from 'vue' | ||
|
||
export const useHasScrollPastThreshold = (): { hasScrolledPastThreshold: Ref<boolean> } => { | ||
const hasScrolledPastThresholdFlag = ref(false); | ||
const scrollOffset = 100; | ||
const { data: scrollPositionsMap } = useState('scroll', ['data']); | ||
const mainScrollPosition = computed(() => scrollPositionsMap.value['main-scroll']?.position); | ||
const hasScrolledPastThresholdFlag = ref(false) | ||
const scrollOffset = 100 | ||
const { data: scrollPositionsMap } = useState('scroll', ['data']) | ||
const mainScrollPosition = computed( | ||
() => scrollPositionsMap.value['main-scroll']?.position as number, | ||
) | ||
|
||
const hasScrolledPastThreshold = computed(() => hasScrolledPastThresholdFlag.value); | ||
const hasScrolledPastThreshold = computed(() => hasScrolledPastThresholdFlag.value) | ||
|
||
watch(mainScrollPosition, () => { | ||
const mainScrollData = scrollPositionsMap.value['main-scroll']; | ||
const mainScrollData = scrollPositionsMap.value['main-scroll'] as ScrollComponentState | ||
|
||
if (mainScrollData?.hasReachedStart) { | ||
hasScrolledPastThresholdFlag.value = false; | ||
return; | ||
hasScrolledPastThresholdFlag.value = false | ||
return | ||
} else { | ||
hasScrolledPastThresholdFlag.value = true; | ||
hasScrolledPastThresholdFlag.value = true | ||
} | ||
|
||
const isScrollingUp = mainScrollData?.direction === 'UP'; | ||
const isScrollingUp = mainScrollData?.direction === 'UP' | ||
if (isScrollingUp || mainScrollPosition.value < scrollOffset) { | ||
hasScrolledPastThresholdFlag.value = false; | ||
hasScrolledPastThresholdFlag.value = false | ||
} else if (!isScrollingUp && mainScrollPosition.value > scrollOffset) { | ||
hasScrolledPastThresholdFlag.value = true; | ||
hasScrolledPastThresholdFlag.value = true | ||
} | ||
}); | ||
}) | ||
|
||
return { | ||
hasScrolledPastThreshold | ||
}; | ||
}; | ||
hasScrolledPastThreshold, | ||
} | ||
} |
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.