问题描述
我有几种视图,我已经实现了一种方法,供用户在屏幕上拖动它们以将其放置在所需的位置。每个视图内部都有一个可编辑的文本字段。 (想想便签)。
为了将粘滞便笺放在用户想要的位置,我使用transform style属性转换X和Y位置。直到我将这些便条纸放入滚动视图中,此方法才能很好地工作。
它在IOS上可以正常工作。在android上,每当用户编辑或关注便笺中的可编辑字段时,滚动视图就会滚动到屏幕顶部。我相信这是因为在android上ScrollView由于转换样式属性不知道TextInput的位置已更改。
我已经搜索了ScrollView的文档,甚至都没有提到文本编辑功能的自动滚动。更不用说如何禁用它了。
有没有一种方法可以防止ScrollView在聚焦或编辑时自动滚动到TextInput?
有没有办法让ScrollView知道TextInput已移动?
以下是出现此问题的屏幕的最小示例:
import * as React from 'react';
import {TextInput,StyleSheet,ScrollView,View} from 'react-native';
export default function BadAutoScrollScreen(props) {
return (
<View style={styles.container}>
<ScrollView style={styles.scroll} contentContainerStyle={styles.contentContainer}>
<View style={styles.transformedView}>
<TextInput>Some Text to Edit</TextInput>
</View>
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
width: '100%',height: '100%',},scroll: {
width: '100%',backgroundColor: 'black',position:'absolute',contentContainer: {
paddingTop: 15,height: 2000,transformedView: {
width:'100%',height:100,justifyContent: 'center',backgroundColor: 'orange',borderRadius: 15,alignItems: 'center',transform: [
{translateY: 800},]
},});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)