From b8dce282d61ef07cdbba3ed751e38f77da213b22 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Wed, 30 Aug 2023 17:32:42 +0300 Subject: [PATCH] fix: Sticky functionality on domain page --- src/screens/DomainView.tsx | 178 +++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 85 deletions(-) diff --git a/src/screens/DomainView.tsx b/src/screens/DomainView.tsx index dd060f9..b344a1b 100644 --- a/src/screens/DomainView.tsx +++ b/src/screens/DomainView.tsx @@ -7,7 +7,6 @@ import { ScrollView, Platform, NativeScrollEvent, - Dimensions, } from "react-native"; import { AntDesign, @@ -31,9 +30,9 @@ import { serializeRecord, serializeSolRecord, } from "@bonfida/spl-name-service"; +import { isMobile } from "@src/utils/platform"; import { ROOT_DOMAIN } from "@bonfida/name-offers"; import { PublicKey, TransactionInstruction } from "@solana/web3.js"; -import SkeletonContent from "react-native-skeleton-content"; import Clipboard from "@react-native-clipboard/clipboard"; import { useModal } from "react-native-modalfy"; import { useProfilePic } from "@bonfida/sns-react"; @@ -469,11 +468,13 @@ export const DomainView = ({ domain }: { domain: string }) => { setScrollViewMeasurements(event.nativeEvent)} + onScroll={(event) => { + event.persist(); + setScrollViewMeasurements(event.nativeEvent); + }} > {isTokenized && ( { {/* This bars are sticky using stickyHeaderIndices */} - - - { - scrollViewRef.current?.scrollTo({ - // -24 so there will be some space between header and field - y: UISectionsCoordinates.socials - 35, - animated: true, - }); - }} - style={[ - tw`px-2 py-1 rounded-xl`, - isSocialsTabHighlighted && tw`bg-background-secondary`, - ]} - > - {t`Socials`} - - { - scrollViewRef.current?.scrollTo({ - // -24 so there will be some space between header and field - y: UISectionsCoordinates.addresses - 24, - animated: true, - }); - }} - style={[ - tw`px-2 py-1 rounded-xl`, - isAddressesTabHighlighted && tw`bg-background-secondary`, - ]} - > - {t`Addresses`} - - {!isSubdomain && ( + {/* The `View` wrapper shouldn't not have `style` cause it will be ignored on mobile */} + + + { scrollViewRef.current?.scrollTo({ - y: UISectionsCoordinates.subdomains, + // -24 so there will be some space between header and field + y: UISectionsCoordinates.socials - 35, animated: true, }); }} style={[ tw`px-2 py-1 rounded-xl`, - isSubdomainsTabHighlighted && tw`bg-background-secondary`, + isSocialsTabHighlighted && tw`bg-background-secondary`, ]} > - - {t`Subdomains`} - + {t`Socials`} - )} - - - {!isTokenized && ( - <> - {isOwner ? ( - { + scrollViewRef.current?.scrollTo({ + // -24 so there will be some space between header and field + y: UISectionsCoordinates.addresses - 24, + animated: true, + }); + }} + style={[ + tw`px-2 py-1 rounded-xl`, + isAddressesTabHighlighted && tw`bg-background-secondary`, + ]} + > + {t`Addresses`} + + {!isSubdomain && ( + { - isEditing ? discardChanges() : toggleEditMode(true); + scrollViewRef.current?.scrollTo({ + y: UISectionsCoordinates.subdomains, + animated: true, + }); }} + style={[ + tw`px-2 py-1 rounded-xl`, + isSubdomainsTabHighlighted && tw`bg-background-secondary`, + ]} > - {isEditing ? ( - - ) : ( - - )} - - ) : ( - - + + {t`Subdomains`} + )} - - )} + + + {!isTokenized && ( + <> + {isOwner ? ( + { + isEditing ? discardChanges() : toggleEditMode(true); + }} + > + {isEditing ? ( + + ) : ( + + )} + + ) : ( + + + + )} + + )} + {[...formState.keys()].map((item) => ( @@ -670,6 +676,7 @@ export const DomainView = ({ domain }: { domain: string }) => { setStatus({ status: "success", message: t`Copied!` }); }} onLayout={(event) => { + event.persist(); if (item === SNSRecord.Backpack) { setCoordinates((prevState) => ({ ...prevState, @@ -753,9 +760,10 @@ export const DomainView = ({ domain }: { domain: string }) => { { + event.persist(); setCoordinates((prevState) => ({ ...prevState, - subdomains: event.nativeEvent?.layout?.y || 0, + subdomains: event.nativeEvent.layout.y, })); }} >