fix: bug
This commit is contained in:
@@ -6,12 +6,11 @@ import {
|
||||
StyleSheet,
|
||||
Platform,
|
||||
ActivityIndicator,
|
||||
ScrollView,
|
||||
KeyboardAvoidingView,
|
||||
} from 'react-native'
|
||||
import { Image } from 'expo-image'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import * as ImagePicker from 'expo-image-picker'
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'
|
||||
|
||||
import { Button } from './ui/button'
|
||||
import Text from './ui/Text'
|
||||
@@ -81,10 +80,12 @@ interface DynamicFormProps {
|
||||
loading?: boolean
|
||||
onOpenDrawer?: (nodeId: string) => void
|
||||
points?: number
|
||||
/** 当外层已有滚动视图时,禁用内部滚动 */
|
||||
disableScroll?: boolean
|
||||
}
|
||||
|
||||
export const DynamicForm = forwardRef<DynamicFormRef, DynamicFormProps>(
|
||||
function DynamicForm({ formSchema, onSubmit, loading = false, onOpenDrawer, points }, ref) {
|
||||
function DynamicForm({ formSchema, onSubmit, loading = false, onOpenDrawer, points, disableScroll = false }, ref) {
|
||||
const { t } = useTranslation()
|
||||
const startNodes = formSchema.startNodes || []
|
||||
|
||||
@@ -456,55 +457,60 @@ export const DynamicForm = forwardRef<DynamicFormRef, DynamicFormProps>(
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={styles.keyboardAvoidingView}
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
||||
keyboardVerticalOffset={0}
|
||||
>
|
||||
<ScrollView
|
||||
style={styles.scrollView}
|
||||
contentContainerStyle={styles.scrollContent}
|
||||
showsVerticalScrollIndicator={false}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
>
|
||||
{startNodes.map(renderField)}
|
||||
const formContent = (
|
||||
<>
|
||||
{startNodes.map(renderField)}
|
||||
|
||||
<View style={styles.submitButtonContainer}>
|
||||
<Button
|
||||
testID="submit-button"
|
||||
variant="gradient"
|
||||
onPress={handleSubmit}
|
||||
disabled={loading}
|
||||
style={styles.submitButton}
|
||||
className="px-0"
|
||||
>
|
||||
{loading ? (
|
||||
<ActivityIndicator color="#fff" />
|
||||
) : (
|
||||
<View style={styles.submitButtonContent}>
|
||||
<Text style={styles.submitButtonText}>
|
||||
{t('dynamicForm.submit') || '提交'}
|
||||
</Text>
|
||||
{points !== undefined && points > 0 && (
|
||||
<View style={styles.pointsContainer}>
|
||||
<Text style={styles.pointsText}>{points}</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
<View style={styles.submitButtonContainer}>
|
||||
<Button
|
||||
testID="submit-button"
|
||||
variant="gradient"
|
||||
onPress={handleSubmit}
|
||||
disabled={loading}
|
||||
style={styles.submitButton}
|
||||
className="px-0"
|
||||
>
|
||||
{loading ? (
|
||||
<ActivityIndicator color="#fff" />
|
||||
) : (
|
||||
<View style={styles.submitButtonContent}>
|
||||
<Text style={styles.submitButtonText}>
|
||||
{t('dynamicForm.submit') || '提交'}
|
||||
</Text>
|
||||
{points !== undefined && points > 0 && (
|
||||
<View style={styles.pointsContainer}>
|
||||
<Text style={styles.pointsText}>{points}</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</>
|
||||
)
|
||||
|
||||
// 当外层已有滚动视图时,不使用内部滚动
|
||||
if (disableScroll) {
|
||||
return (
|
||||
<View style={styles.scrollContent}>
|
||||
{formContent}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<KeyboardAwareScrollView
|
||||
style={styles.scrollView}
|
||||
contentContainerStyle={styles.scrollContent}
|
||||
bottomOffset={50}
|
||||
>
|
||||
{formContent}
|
||||
</KeyboardAwareScrollView>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
keyboardAvoidingView: {
|
||||
flex: 1,
|
||||
},
|
||||
scrollView: {
|
||||
flex: 1,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user