Is it possible to keep a ScrollView scrolled to the bottom?

前端 未结 16 1314
误落风尘
误落风尘 2020-12-04 17:13

For a chat-like app, I want to keep a ScrollView component scrolled to the bottom, because newest messages appear under the older ones. Can we adjust the scroll

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 18:02

    For anyone writing function component that can use hook,

    import React, { useRef } from 'react';
    import { ScrollView } from 'react-native';
    
    const ScreenComponent = (props) => {
      const scrollViewRef = useRef();
      return (
         scrollViewRef.current.scrollToEnd({ animated: true })}
        />
      );
    };
    

提交回复
热议问题