首页 > 解决方案 > 如何找到组件位置尺寸并向下滚动?

问题描述

我想找出 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: "일론머스크&quot;}
                    UserId: 2
                    active: "1"
                    content: "hello"
                    createdAt: "2021-03-16T10:30:30.000Z"
                    id: 132
                    updatedAt: "2021-03-17T08:05:02.000Z"}

标签: javascriptnode.jsreactjsreact-nativereact-redux

解决方案


推荐阅读