diff --git a/app/src/form/components/Question.js b/app/src/form/components/Question.js index bfa40cfaf..0c8259080 100644 --- a/app/src/form/components/Question.js +++ b/app/src/form/components/Question.js @@ -1,4 +1,4 @@ -import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'; +import React, { memo, useCallback, useEffect, useMemo, useState, useRef } from 'react'; import { FlatList, View } from 'react-native'; import * as Crypto from 'expo-crypto'; import QuestionField from './QuestionField'; @@ -13,6 +13,7 @@ const Question = memo(({ group }) => { */ const [preload, setPreload] = useState(true); const values = FormState.useState((s) => s.currentValues); + const flatListRef = useRef(null); const questions = useMemo(() => { try { @@ -77,8 +78,16 @@ const Question = memo(({ group }) => { handleOnGenerateUUID(); }, [handleOnGenerateUUID]); + + useEffect(() => { + if (flatListRef.current) { + flatListRef.current.scrollToOffset({ animated: true, offset: 0 }); + } + }, [questions]); + return ( `question-${item.id}`}