Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
Swipe down do refresh on regular View in react native app

Is there a way to do a swipe down to refresh in react native on a regular view without using something like a FlatList or ScrollView ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is no built-in solution for doing this. We usually want some kind of feedback for the user, thus the regular pull to refresh action is a suitable choice and this obviously only works in some kind of scrollable container.

However, if we still do not want to use a ScrollView for this purpose, then we could listen to touch gestures and react after a certain treshold as follows.

const SomeRefreshableNonScrollableComponent = (props) => {
   const y = useRef()

   function onRefresh() {
        // refresh or whatever
   }

   return (
    <View
      style={{flex :1}}
      onTouchStart={e=> y.current = e.nativeEvent.pageY}
      onTouchEnd={e => {
        // some threshold. add whatever suits you
        if (y.current - e.nativeEvent.pageY < 40) {
          onRefresh()
        }
      }}>

     ...

    </View>
  )
}

Edit: As an answer to the comments.

We can implement a pull down to refresh mechanism for a FlatList that is nested inside a not scrollable ScrollView as follows.

const [data, setData] = useState([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  const [refresh, setRefresh] = useState(false)

  useEffect(() => {

    if (refresh) {
      console.log("Refresh my inner data on pull")
    }
  }, [refresh])

  return (
    <ScrollView scrollEnabled={false} nestedScrollEnabled={true}>
      <FlatList refreshing={refresh} onRefresh={() => setRefresh(true)} data={data} renderItem={({item}) => {
        return <Text>Hello world</Text>
      }} />
    </ScrollView>
  );
};

Notice that you must reset your refresh state back to false once your refresh action is done, e.g. if an API call returns its data. Otherwise, the Flatlist will keep showing the refresh indicator.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda