-
Notifications
You must be signed in to change notification settings - Fork 1k
[#22580] Help community owners to make their community visible #22590
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
Open
ulisesmac
wants to merge
16
commits into
develop
Choose a base branch
from
22580-help-owners-make-their-community-visible
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4319646
Address Pedro's feedback on animation timing
ulisesmac 28d7773
Add :right-icon option for the button inside the information box comp…
ulisesmac abca1e3
Add an info box for community owners to promote their community
ulisesmac 6b734fd
Adjust page-nav layout for Android
ulisesmac 4f8c041
Scroll fixed
ulisesmac ba5f093
WIP: simplification
ulisesmac f9f5025
Refactor done, pending perf. improvement
ulisesmac bafded2
Add sub to improve performance
ulisesmac 6949477
Improve responsiveness and performance
ulisesmac 8b0870d
Lint fix
ulisesmac 545a06a
Mock new worklets
ulisesmac 3efe4d5
Lint fix
ulisesmac 2b38878
Fix arity
ulisesmac a93d385
Fix code style for comments
ulisesmac 16bedf0
Improve name
ulisesmac e0bef37
Lint fix
ulisesmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,20 +10,45 @@ import { | |
|
|
||
| import { Platform } from 'react-native'; | ||
|
|
||
| export function useStartScrollValue(isCollapsed, collapseThreshold) { | ||
| return useDerivedValue(() => { | ||
| return isCollapsed ? -collapseThreshold.value : 0; | ||
| }); | ||
| } | ||
|
|
||
| export function useScrollValue(isCollapsed, collapseThreshold) { | ||
| return useDerivedValue(() => { | ||
| return isCollapsed ? collapseThreshold.value : 0; | ||
| }); | ||
| } | ||
|
|
||
| export function useDerivedValueAdd(sharedValue, value) { | ||
| return useDerivedValue(() => { | ||
| return sharedValue.value + value; | ||
| }); | ||
| } | ||
|
|
||
| export function useDerivedValueMul(sharedValue, value) { | ||
| return useDerivedValue(() => { | ||
| return sharedValue.value * value; | ||
| }); | ||
| } | ||
|
|
||
| export function useLogoStyles({ | ||
| initialState, | ||
| scrollAmount, | ||
| expandHeaderThreshold, | ||
| collapseThreshold, | ||
| sheetDisplacementThreshold, | ||
| textMovementThreshold, | ||
| }) { | ||
| return useAnimatedStyle(() => { | ||
| const firstDisplacement = scrollAmount.value < expandHeaderThreshold; | ||
| if (firstDisplacement) { | ||
| const isFirstDisplacement = initialState.value === 'expanded' || scrollAmount.value < collapseThreshold.value; | ||
| if (isFirstDisplacement) { | ||
| return { | ||
| transform: [ | ||
| { translateX: 20 }, | ||
| { translateY: interpolate(scrollAmount.value, [0, expandHeaderThreshold], [0, -42.5], 'clamp') }, | ||
| { scale: interpolate(scrollAmount.value, [0, textMovementThreshold], [1, 0.4], 'clamp') }, | ||
| { translateY: interpolate(scrollAmount.value, [0, collapseThreshold.value], [0, -42.5], 'clamp') }, | ||
| { scale: interpolate(scrollAmount.value, [0, textMovementThreshold.value], [1, 0.4], 'clamp') }, | ||
| ], | ||
| }; | ||
| } else { | ||
|
|
@@ -33,7 +58,7 @@ export function useLogoStyles({ | |
| { | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [expandHeaderThreshold, sheetDisplacementThreshold], | ||
| [collapseThreshold.value, sheetDisplacementThreshold.value], | ||
| [-42.5, -50.5], | ||
| 'clamp', | ||
| ), | ||
|
|
@@ -45,19 +70,19 @@ export function useLogoStyles({ | |
| }); | ||
| } | ||
|
|
||
| export function useSheetStyles({ scrollAmount, expandHeaderThreshold, sheetDisplacementThreshold }) { | ||
| export function useSheetStyles({ initialState, scrollAmount, collapseThreshold, sheetDisplacementThreshold }) { | ||
| return useAnimatedStyle(() => { | ||
| const firstDisplacement = scrollAmount.value < expandHeaderThreshold; | ||
| if (firstDisplacement) { | ||
| const isFirstDisplacement = initialState.value === 'expanded' || scrollAmount.value < collapseThreshold.value; | ||
| if (isFirstDisplacement) { | ||
| return { | ||
| transform: [{ translateY: interpolate(scrollAmount.value, [0, expandHeaderThreshold], [40, 0], 'clamp') }], | ||
| transform: [{ translateY: interpolate(scrollAmount.value, [0, collapseThreshold.value], [40, 0], 'clamp') }], | ||
| borderTopLeftRadius: 20, | ||
| borderTopRightRadius: 20, | ||
| }; | ||
| } else { | ||
| const radius = interpolate( | ||
| scrollAmount.value, | ||
| [expandHeaderThreshold, sheetDisplacementThreshold], | ||
| [collapseThreshold.value, sheetDisplacementThreshold.value], | ||
| [20, 0], | ||
| 'clamp', | ||
| ); | ||
|
|
@@ -66,7 +91,7 @@ export function useSheetStyles({ scrollAmount, expandHeaderThreshold, sheetDispl | |
| { | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [expandHeaderThreshold, sheetDisplacementThreshold], | ||
| [collapseThreshold.value, sheetDisplacementThreshold.value], | ||
| [0, -8], | ||
| 'clamp', | ||
| ), | ||
|
|
@@ -79,55 +104,81 @@ export function useSheetStyles({ scrollAmount, expandHeaderThreshold, sheetDispl | |
| }); | ||
| } | ||
|
|
||
| export function useNameStyles({ scrollAmount, expandHeaderThreshold, textMovementThreshold }) { | ||
| export function useNameStyles({ initialState, scrollAmount, collapseThreshold, textMovementThreshold }) { | ||
| return useAnimatedStyle(() => { | ||
| const animationProgress = interpolate( | ||
| scrollAmount.value, | ||
| [textMovementThreshold, expandHeaderThreshold], | ||
| [0, 40], | ||
| 'clamp', | ||
| ); | ||
| let horizontalPosition; | ||
| if (initialState.value === 'collapsed') { | ||
| horizontalPosition = 40; | ||
| } else if (initialState.value === 'expanded') { | ||
| horizontalPosition = 0; | ||
| } else { | ||
| horizontalPosition = interpolate( | ||
| scrollAmount.value, | ||
| [textMovementThreshold.value, collapseThreshold.value], | ||
| [0, 40], | ||
| 'clamp', | ||
| ); | ||
| } | ||
|
|
||
| let verticalPosition; | ||
| if (initialState.value === 'collapsed') { | ||
| verticalPosition = -44.5; | ||
| } else if (initialState.value === 'expanded') { | ||
| verticalPosition = 0; | ||
| } else { | ||
| verticalPosition = interpolate( | ||
| scrollAmount.value, | ||
| [textMovementThreshold.value, collapseThreshold.value], | ||
| [0, -44.5], | ||
| 'clamp', | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| marginRight: animationProgress, | ||
| transform: [ | ||
| { translateX: animationProgress }, | ||
| { | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [textMovementThreshold, expandHeaderThreshold], | ||
| [0, -44.5], | ||
| 'clamp', | ||
| ), | ||
| }, | ||
| ], | ||
| marginRight: horizontalPosition, | ||
| transform: [{ translateX: horizontalPosition }, { translateY: verticalPosition }], | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| export function useInfoStyles({ scrollAmount, infoOpacityThreshold }) { | ||
| export function useInfoStyles({ initialState, scrollAmount, collapseThreshold, infoOpacityThresholdFactor }) { | ||
| return useAnimatedStyle(() => { | ||
| let opacity; | ||
| if (initialState.value === 'collapsed') { | ||
| opacity = 0; | ||
| } else if (initialState.value === 'expanded') { | ||
| opacity = 1; | ||
|
Comment on lines
+147
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure who is choosing the names for |
||
| } else { | ||
| const infoOpacityThreshold = collapseThreshold.value * infoOpacityThresholdFactor; | ||
| opacity = interpolate(scrollAmount.value, [0, infoOpacityThreshold], [1, 0.2], 'extend'); | ||
| } | ||
| return { | ||
| opacity: interpolate(scrollAmount.value, [0, infoOpacityThreshold], [1, 0.2], 'extend'), | ||
| opacity: opacity, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| export function useChannelsStyles({ | ||
| scrollAmount, | ||
| headerHeight, | ||
| expandHeaderThreshold, | ||
| collapseThreshold, | ||
| sheetDisplacementThreshold, | ||
| expandHeaderLimit, | ||
| }) { | ||
| return useAnimatedStyle(() => { | ||
| const headerDisplacement = (headerHeight.value - 55.5) * -1; | ||
| const firstDisplacement = scrollAmount.value < expandHeaderThreshold; | ||
| const secondDisplacement = scrollAmount.value > sheetDisplacementThreshold; | ||
| const firstDisplacement = scrollAmount.value < collapseThreshold.value; | ||
| const secondDisplacement = scrollAmount.value > sheetDisplacementThreshold.value; | ||
| if (firstDisplacement) { | ||
| return { | ||
| transform: [ | ||
| { | ||
| translateY: interpolate(scrollAmount.value, [0, expandHeaderThreshold], [39, headerDisplacement], 'clamp'), | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [0, collapseThreshold.value], | ||
| [39, headerDisplacement], | ||
| 'clamp', | ||
| ), | ||
| }, | ||
| ], | ||
| }; | ||
|
|
@@ -137,7 +188,7 @@ export function useChannelsStyles({ | |
| { | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [sheetDisplacementThreshold, expandHeaderLimit], | ||
| [sheetDisplacementThreshold.value, expandHeaderLimit.value], | ||
| [headerDisplacement - 8, headerDisplacement - 64], | ||
| 'clamp', | ||
| ), | ||
|
|
@@ -150,27 +201,32 @@ export function useChannelsStyles({ | |
| { | ||
| translateY: interpolate( | ||
| scrollAmount.value, | ||
| [expandHeaderThreshold, sheetDisplacementThreshold], | ||
| [collapseThreshold.value, sheetDisplacementThreshold.value], | ||
| [headerDisplacement, headerDisplacement - 8], | ||
| 'clamp', | ||
| ), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| }, [headerHeight.value]); | ||
| }); | ||
| } | ||
|
|
||
| export function useScrollTo({ animatedRef, scrollAmount, expandHeaderLimit }) { | ||
| const isAndroid = Platform.OS === 'android'; | ||
| return useDerivedValue(() => { | ||
| scrollTo(animatedRef, 0, scrollAmount.value - expandHeaderLimit, isAndroid); | ||
| scrollTo(animatedRef, 0, scrollAmount.value - expandHeaderLimit.value, isAndroid); | ||
| }); | ||
| } | ||
|
|
||
| export function useHeaderOpacity({ scrollAmount, expandHeaderThreshold, sheetDisplacementThreshold }) { | ||
| export function useHeaderOpacity({ scrollAmount, collapseThreshold, sheetDisplacementThreshold }) { | ||
| return useDerivedValue(() => { | ||
| return interpolate(scrollAmount.value, [expandHeaderThreshold, sheetDisplacementThreshold], [0, 1], 'clamp'); | ||
| return interpolate( | ||
| scrollAmount.value, | ||
| [collapseThreshold.value, sheetDisplacementThreshold.value], | ||
| [0, 1], | ||
| 'clamp', | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -180,9 +236,15 @@ export function useOppositeHeaderOpacity(headerOpacity) { | |
| }); | ||
| } | ||
|
|
||
| export function useNavContentOpacity({ scrollAmount, sheetDisplacementThreshold, expandHeaderLimit }) { | ||
| export function useNavContentOpacity({ | ||
| scrollAmount, | ||
| navbarContentThresholdFactor, | ||
| sheetDisplacementThreshold, | ||
| expandHeaderLimit, | ||
| }) { | ||
| return useDerivedValue(() => { | ||
| return interpolate(scrollAmount.value, [sheetDisplacementThreshold, expandHeaderLimit], [0, 1], 'clamp'); | ||
| const navbarContentThreshold = sheetDisplacementThreshold.value + navbarContentThresholdFactor; | ||
| return interpolate(scrollAmount.value, [navbarContentThreshold, expandHeaderLimit.value], [0, 1], 'clamp'); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -240,7 +302,7 @@ export function onPanUpdate({ scrollStart, scrollAmount, maxScroll, expandHeader | |
| if (newScrollAmount <= 0) { | ||
| scrollAmount.value = 0; | ||
| } else { | ||
| const limit = expandHeaderLimit + maxScroll.value; | ||
| const limit = expandHeaderLimit.value + maxScroll.value; | ||
| scrollAmount.value = newScrollAmount <= limit ? newScrollAmount : limit; | ||
| } | ||
| }; | ||
|
|
@@ -251,26 +313,27 @@ export function onPanEnd({ | |
| scrollAmount, | ||
| maxScroll, | ||
| expandHeaderLimit, | ||
| expandHeaderThreshold, | ||
| snapHeaderThreshold, | ||
| collapseThreshold, | ||
| snapHeaderThresholdFactor, | ||
| animationDuration, | ||
| }) { | ||
| const isIOS = Platform.OS === 'ios'; | ||
| return function (event) { | ||
| 'worklet'; | ||
| scrollStart.value = -scrollAmount.value; | ||
| const snapHeaderThreshold = collapseThreshold.value * snapHeaderThresholdFactor; | ||
| const endAnimation = onScrollAnimationEnd( | ||
| scrollAmount, | ||
| scrollStart, | ||
| expandHeaderThreshold, | ||
| collapseThreshold.value, | ||
| snapHeaderThreshold, | ||
| expandHeaderLimit, | ||
| expandHeaderLimit.value, | ||
| animationDuration, | ||
| ); | ||
| if (scrollAmount.value < expandHeaderLimit) { | ||
| if (scrollAmount.value < expandHeaderLimit.value) { | ||
| endAnimation(); | ||
| } else { | ||
| const maxValue = maxScroll.value + expandHeaderLimit; | ||
| const maxValue = maxScroll.value + expandHeaderLimit.value; | ||
| const decelerationRate = isIOS ? { deceleration: 0.998 } : { deceleration: 0.996 }; | ||
|
|
||
| scrollStart.value = withDecay({ | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny comment: Maybe we can create a helper function for computing
isFirstDisplacement?