Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 23 additions & 35 deletions app/src/screens/verification/ProveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
NativeSyntheticEvent,
ScrollView as ScrollViewType,
} from 'react-native';
import { StyleSheet } from 'react-native';
import { Platform, StyleSheet } from 'react-native';
import { View, YStack } from 'tamagui';
import type { RouteProp } from '@react-navigation/native';
import {
Expand Down Expand Up @@ -78,7 +78,6 @@ const ProveScreen: React.FC = () => {
const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false);
const [scrollViewContentHeight, setScrollViewContentHeight] = useState(0);
const [scrollViewHeight, setScrollViewHeight] = useState(0);
const [hasLayoutMeasurements, setHasLayoutMeasurements] = useState(false);
const [isDocumentExpired, setIsDocumentExpired] = useState(false);
const [documentType, setDocumentType] = useState('');
const [walletModalOpen, setWalletModalOpen] = useState(false);
Expand All @@ -91,13 +90,21 @@ const ProveScreen: React.FC = () => {
);

const isScrollable = useMemo(
() => !isContentShorterThanScrollView && hasLayoutMeasurements,
[isContentShorterThanScrollView, hasLayoutMeasurements],
() => !isContentShorterThanScrollView,
[isContentShorterThanScrollView],
);
const provingStore = useProvingStore();
const currentState = useProvingStore(state => state.currentState);
const isReadyToProve = currentState === 'ready_to_prove';

const initialScrollOffset = useMemo(() => {
if (route.params?.scrollOffset === undefined) {
return undefined;
}
const padding = Platform.OS === 'ios' ? 3 : 15;
return route.params.scrollOffset + padding;
}, [route.params?.scrollOffset]);

const { addProofHistory } = useProofHistoryStore();
const { loadDocumentCatalog } = usePassport();

Expand Down Expand Up @@ -126,15 +133,13 @@ const ProveScreen: React.FC = () => {
}, [addProofHistory, loadDocumentCatalog, provingStore.uuid, selectedApp]);

useEffect(() => {
// Only update hasScrolledToBottom once we have real layout measurements
if (hasLayoutMeasurements) {
if (isContentShorterThanScrollView) {
setHasScrolledToBottom(true);
} else {
setHasScrolledToBottom(false);
}
// Update hasScrolledToBottom based on content size
if (isContentShorterThanScrollView) {
setHasScrolledToBottom(true);
} else {
setHasScrolledToBottom(false);
}
}, [isContentShorterThanScrollView, hasLayoutMeasurements]);
}, [isContentShorterThanScrollView]);

useEffect(() => {
if (!isFocused || !selectedApp) {
Expand Down Expand Up @@ -282,31 +287,14 @@ const ProveScreen: React.FC = () => {
const handleContentSizeChange = useCallback(
(contentWidth: number, contentHeight: number) => {
setScrollViewContentHeight(contentHeight);
// If we now have both measurements and content fits on screen, enable button immediately
if (contentHeight > 0 && scrollViewHeight > 0) {
setHasLayoutMeasurements(true);
if (contentHeight <= scrollViewHeight + 50) {
setHasScrolledToBottom(true);
}
}
},
[scrollViewHeight],
[],
);

const handleScrollViewLayout = useCallback(
(event: LayoutChangeEvent) => {
const layoutHeight = event.nativeEvent.layout.height;
setScrollViewHeight(layoutHeight);
// If we now have both measurements and content fits on screen, enable button immediately
if (layoutHeight > 0 && scrollViewContentHeight > 0) {
setHasLayoutMeasurements(true);
if (scrollViewContentHeight <= layoutHeight + 50) {
setHasScrolledToBottom(true);
}
}
},
[scrollViewContentHeight],
);
const handleScrollViewLayout = useCallback((event: LayoutChangeEvent) => {
const layoutHeight = event.nativeEvent.layout.height;
setScrollViewHeight(layoutHeight);
}, []);

return (
<View style={styles.container}>
Expand All @@ -333,7 +321,7 @@ const ProveScreen: React.FC = () => {
scrollViewRef={scrollViewRef}
onContentSizeChange={handleContentSizeChange}
onLayout={handleScrollViewLayout}
initialScrollOffset={route.params?.scrollOffset}
initialScrollOffset={initialScrollOffset}
testID="prove-screen-card"
>
{/* Disclosure Items */}
Expand Down
Loading