javascript - 如何找到组件位置尺寸并向下滚动?
问题描述
我想找出 TodoItem 组件中 HiContainer 位置的维度,并使用 useEffect 和 scrollToOffset 向下滚动。有办法吗??我应该添加和修复什么代码?......
这是我的代码
(TodoList.js)
const TodoList = ({}) => {
const height = Dimensions.get('window').height;
const flatListRef = useRef()
useEffect(() => {
setTimeout(() => {
const node = flatListRef.current;
node.scrollToOffset({ offset:???, animated: true });
},400);
},[]);
return (
<FlatList
ref={flatListRef}
style={{height}}
renderItem={({item}) => (
<TodoItem
style={{height}}
item={item}
replycomment={replycomment}
contentOffset={{x: 0, y: height}}
/>
)}
/>
(TodoItem.js)
const TodoItem = ({replycomment}) => {
console.log("replycomment:",replycomment);
return (
<>
<HiContainer>
<ReplyUserName>{replycomment.User.nickname}</ReplyUserName>
<ReplyLabel>{replycomment.content}</ReplyLabel>
</HiContainer>
</>
);
};
回复评论中有这样的数据
console.log replycomment : {CommentId: 88
PostId: 2
ReplyCommentId: 56
User: {id: 2, nickname: "일론머스크"}
UserId: 2
active: "1"
content: "hello"
createdAt: "2021-03-16T10:30:30.000Z"
id: 132
updatedAt: "2021-03-17T08:05:02.000Z"}
解决方案
推荐阅读
- c# - ASP.NET Core 2 MVC 选择标记帮助程序(下拉) 所选项目并不总是反映值
- office-js - 无法更改主页功能区上 Excel 中的默认图标
- php - 层次树按字母排序
- python - 在数据框中查找非日期
- r - 用于位置映射的 rvest 和 xpath 抓取表
- excel - SSIS:使用文件系统任务复制文件后无法写入 Excel 文件 (.xlsx)
- python - 最佳实践 Python - 存储 API KEYS/TOKENS 的位置
- java - 为什么在尝试打印 Derived 字段时未编译由类 Base 引用引用的 Derived 类的对象?
- python - Django rest 不断收到 AssertionError: 'ListCreateAPIView' 应该包含一个 `queryset` 属性,或者覆盖 `get_queryset()` 方法
- xcode - 找不到 iOS 12.3.1 模拟器