All Projects → 4TWIGGERS → react-native-fresh-refresh

4TWIGGERS / react-native-fresh-refresh

Licence: MIT license
custom pull to refresh component

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-fresh-refresh

mask export
Export your mask elements as extension
Stars: ✭ 45 (-69.39%)
Mutual labels:  custom
E-Table
基于ElementUI table组件修改,数据化表格结构,添加实用功能,快速生成表格
Stars: ✭ 65 (-55.78%)
Mutual labels:  custom
uptime-card
Minimalistic uptime card for Home Assistant Lovelace UI
Stars: ✭ 152 (+3.4%)
Mutual labels:  custom
android manifest
The beginnings
Stars: ✭ 26 (-82.31%)
Mutual labels:  custom
mltools
MLDB Unity Editor Bindings
Stars: ✭ 22 (-85.03%)
Mutual labels:  custom
dotEngine-android-sdk-example
dotEngine android sdk example
Stars: ✭ 29 (-80.27%)
Mutual labels:  custom
KKRefreshLayout
An android refresh layout, support custom vertical/horizontal refresh.
Stars: ✭ 13 (-91.16%)
Mutual labels:  custom
RMGradientView
A Custom Gradient View Control for iOS with inspectable properties.
Stars: ✭ 24 (-83.67%)
Mutual labels:  custom
kaldi ag training
Docker image and scripts for training finetuned or completely personal Kaldi speech models. Particularly for use with kaldi-active-grammar.
Stars: ✭ 14 (-90.48%)
Mutual labels:  custom
skeleton-loader
Loader module for webpack to execute your custom procedure. It works as your custom loader.
Stars: ✭ 19 (-87.07%)
Mutual labels:  custom
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (-29.93%)
Mutual labels:  custom
RAScrollablePickerView
Lightweight HSB color picker view.
Stars: ✭ 39 (-73.47%)
Mutual labels:  custom
use-images-loaded
🖼️ Returns true once all the images inside a container are loaded
Stars: ✭ 82 (-44.22%)
Mutual labels:  custom
Crazy-Banner
custom banner editor script for Termux
Stars: ✭ 60 (-59.18%)
Mutual labels:  custom
react-reactions
😲 Create custom reaction pickers and counters or use your favorites!
Stars: ✭ 34 (-76.87%)
Mutual labels:  custom
SpinningWheelAndroid
Custom Spinning Wheel View for Android
Stars: ✭ 45 (-69.39%)
Mutual labels:  custom
CustomVideoRecording
Custom video recording based on AVFoundation.
Stars: ✭ 20 (-86.39%)
Mutual labels:  custom
monkey-react-scripts
Monkey react script runner
Stars: ✭ 22 (-85.03%)
Mutual labels:  custom
manifest
This is where the magic begins
Stars: ✭ 29 (-80.27%)
Mutual labels:  custom
JHTAlertController
A custom iOS alert that replaces the stock UIAlertController. Easily style the alert to match your app. Written in Swift for iOS.
Stars: ✭ 58 (-60.54%)
Mutual labels:  custom

react-native-fresh-refresh

Custom pull to refresh Component


Note

react-native-gesture-handler supported by Expo 44 has a bug which breaks fresh refresh

If you are using react-native-gesture-handler version below 2 please install react-native-fresh-refresh 1.1.0


Usage

Step 1

Installation

Use yarn

yarn add react-native-fresh-refresh

or npm

npm i -S react-native-fresh-refresh

Prerequisites

You are going to need to have react-native-reanimated v2 and react-native-gesture-handler installed in your project.

Step 2

import RefreshableWrapper from 'react-native-fresh-refresh';

Step 3

Create Animated List or regular View to use pull to refresh

const AnimatedFlatlist = Animated.createAnimatedComponent(FlatList);



You can disable default styles of loader container passing prop defaultAnimationEnabled={false}

Pass Reanimated sharedValue to get overdrag Y-Offset

const contentOffset = useSharedValue(0);
<RefreshableWrapper
  defaultAnimationEnabled={false}
  contentOffset={contentOffset}
  Loader={() => ({
    <YourAwsomeComponent />
  })}
  isLoading={isLoading}
  bounces
  hitslop={{left: -50}} // Add the gesture hitslop
  managedLoading   // Trigger loading animation on state change 
  onRefresh={() => {
    refreshHandler();
  }}
>
  <AnimatedFlatlist />
</RefreshableWrapper>

Example


import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { StyleSheet, Text, View, FlatList, Dimensions } from 'react-native';
import Animated from 'react-native-reanimated';
import RefreshableWrapper from 'react-native-fresh-refresh';
import LottieView from 'lottie-react-native';

const AnimatedFlatlist = Animated.createAnimatedComponent(FlatList);
const data = ['1', '2', '3', '4', '5', '6'];
const { width } = Dimensions.get('screen');

const EmptyComponent = (props) => {
  return (
    <View>
      <Text>LIST EMPTY COMPONENT</Text>
    </View>
  );
};
const ListItem = (props) => {
  return (
    <View style={{ height: 200 }}>
      <Text>LIST Item COMPONENT</Text>
      <Text> {props.item}</Text>
    </View>
  );
};

export default function App() {
  const [isLoading, setIsLoading] = useState(false);
  const [listData, setListData] = useState([]);

  const refreshSimulationHandler = () => {
    setListData([]);
    setIsLoading(true);
    setTimeout(async () => {
      setListData(data);
      setIsLoading(false);
    }, 1500);
  };

  return (
    <View style={styles.container}>
      <StatusBar style='auto' />
      <View style={styles.header} />
      <RefreshableWrapper
        contentOffset={contentOffset}
        Loader={() => <YourAwsomeComponent />}
        isLoading={isLoading}
        onRefresh={() => {
          refreshSimulationHandler();
        }}
        bounces
      >
        <AnimatedFlatlist
          data={listData}
          keyExtractor={(item) => item}
          renderItem={({ item }) => {
            return <ListItem item={item} />;
          }}
          style={styles.scrollList}
          contentContainerStyle={styles.contenContainer}
          showsVerticalScrollIndicator={false}
          scrollEventThrottle={16}
          ListEmptyComponent={() => <EmptyComponent />}
        />
      </RefreshableWrapper>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  header: { width, height: 100, backgroundColor: 'grey' },
  contenContainer: {
    paddingVertical: 10,
    paddingHorizontal: 16,
    paddingBottom: 100,
    alignItems: 'center',
  },
  lottie: {
    width: 50,
    height: 50,
  },
  scrollList: { width, paddingTop: 20 },
});

Tips

  • If you have gesture conflicts, you can use 'hitslop' to control the trigger timing. see here

Hire us

Contact us at [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].