Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 在TextInput字段中按下时,React Native FlatList | | VirtualizedList从0索引重新启动_React Native_Flatlist - Fatal编程技术网

React native 在TextInput字段中按下时,React Native FlatList | | VirtualizedList从0索引重新启动

React native 在TextInput字段中按下时,React Native FlatList | | VirtualizedList从0索引重新启动,react-native,flatlist,React Native,Flatlist,我需要帮助。我正在用React Native生成一个聊天应用程序,但在向上滚动一些聊天时遇到了一些问题 我一点击文本输入,我的平面列表或虚拟化列表就从索引0开始,这是我不想要的,我期望的是WhatsApp中的情况,在滚动一些距离后,当我们按下输入字段时,它不会滚动到底部,而是静止不动 为此共享视频。 我在这里使用REST国家API复制了这个场景 我没有改变任何状态,因此我认为它不会重新呈现 主要链接: import-React{ useState, useRef, 使用效果, }从"反应",

我需要帮助。我正在用React Native生成一个聊天应用程序,但在向上滚动一些聊天时遇到了一些问题 我一点击文本输入,我的平面列表或虚拟化列表就从索引0开始,这是我不想要的,我期望的是WhatsApp中的情况,在滚动一些距离后,当我们按下输入字段时,它不会滚动到底部,而是静止不动

为此共享视频。

我在这里使用REST国家API复制了这个场景

我没有改变任何状态,因此我认为它不会重新呈现

主要链接:

import-React{
useState,
useRef,
使用效果,
}从"反应",;
进口{
尺寸,
文本,
看法
平面列表,
可触摸不透明度,
文本输入,
样式表,
键盘
虚拟化列表,
Listrenditem,
}从“反应本机”;
从“反应本机矢量图标/离子图标”导入图标;
从“反应本机矢量图标/材料通信图标”导入MTI;
导出接口道具{
}
出口接口货币{
代码:字符串;
名称:字符串;
符号:字符串;
}
导出接口语言{
iso639_1:字符串;
iso639_2:字符串;
名称:字符串;
nativeName:字符串;
}
导出接口翻译{
de:字符串;
es:字符串;
fr:字符串;
ja:字符串;
它:字符串;
br:字符串;
pt:字符串;
nl:字符串;
hr:字符串;
fa:字符串;
}
出口接口区域集团{
缩写:字符串;
名称:字符串;
其他首字母缩略词:string[];
其他名称:字符串[];
}
导出接口根对象{
名称:字符串;
topLevelDomain:字符串[];
字母代码:字符串;
字母代码:字符串;
调用代码:字符串[];
大写:字符串;
交替拼写:字符串[];
区域:字符串;
次区域:字符串;
人口:个;
latlng:编号[];
人名:字符串;
面积?:数字;
基尼:数字;
时区:字符串[];
边框:字符串[];
nativeName:字符串;
数字代码:字符串;
货币:货币【】;;
语文:语文[];
翻译:翻译;
标志:字符串;
区域集团:区域集团[];
cioc:字符串;
键:字符串;
}
常数genericHeight=50;
常量itemLayoutHeights:Array=[];
常量App2:React.FC=({})=>{
const deviceWidth=Dimensions.get('window').width;
const deviceHeight=维度.get('window').height;
const[error,setError]=useState(null);
const[isLoaded,setIsLoaded]=useState(false);
const[allCountryInfo,setAllCountryInfo]=useState();
const[messageInputState,setMessageInputState]=useState(“”);
const partnerchatsvlref=useRef(null);
const messageInputRef=useRef(null);
const onChangeTextLoggerInput=(inputValue:string)=>{
log(`inputValue==>${inputValue}`);
setMessageInputState(inputValue);
};
useffect(()=>{
常量getData=()=>{
常量url=https://restcountries.eu/rest/v2/';
获取(url)
.then(res=>res.json())
.那么(
(结果)=>{
设置错误(空);
setIsLoaded(真);
const allResult=result.map((oneInterest:RootObject)=>({
…一项利益,
关键字:oneInterest.nativeName,
}
)
);
设置所有国家信息(所有结果);
},
(错误3)=>{
setIsLoaded(真);
设置错误(错误3);
setAllCountryInfo([]);
}
).catch((错误2)=>{
log('error2:',error2);
setIsLoaded(真);
setAllCountryInfo([]);
});
};
getData();
}, []);
const renderItemGetItemLayOut:ListRenderItem=({
项目,,
指数
分隔符})=>{
返回(
{
itemLayoutHeights[索引]=object.nativeEvent.layout.height;
}}
>
{index}:{item.name}
);
};
//国民保健服务。。。。英国国民健康保险基金会。。
console.log(“allCountryInfo.length:,allCountryInfo?.length”);
返回(
item.key}
反向={true}
getItemLayout={(数据,索引)=>({
长度:(itemLayoutHeights[索引]==未定义)
? 100
:itemLayoutHeights[索引],
偏移量:itemLayoutHeights.slice(0,索引).reduce((a,c)=>a+c,0),
指数
}
)}
/>
onChangeTextLoggerInput(文本)
}
加压素={
(e) =>{
log(“onPressIn的事件:”,e.target.viewConfig.uiViewClassName);
//e.预防违约();
}
}
聚焦={
(e) =>{
log(“onFocus事件”,e.target.viewConfig.uiViewClassName);
//e.预防违约();
}
}
/>