0Pricing
React Native Academy · Ders

Aşağı Çekerek Yenileme ve Daha Fazla Yükleme

Kullanıcıların verileri yeniden yüklemek için aşağı çekmesine olanak tanımak üzere RefreshControl ile onRefresh uygulayın ve sonuçların sonraki sayfasını almak için onEndReached kullanın.

Aşağı Çekerek Yenileme ve Daha Fazla Yükleme, CoddyKit'te ücretsiz bir React Native Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, React Native Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. React Native Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Pull-to-Refresh?

Pull-to-refresh is a mobile-native gesture where the user pulls the list downward to trigger a data reload. It signals to the app that new content should be fetched from the server. React Native's FlatList has built-in support for this gesture through the onRefresh and refreshing props.

The refreshing and onRefresh Props

FlatList's pull-to-refresh requires two props: refreshing (a boolean that shows or hides the spinner) and onRefresh (a callback that runs your data-fetch logic). Set refreshing to true when the fetch starts and back to false when it completes.

const [refreshing, setRefreshing] = useState(false);

const onRefresh = async () => {
  setRefreshing(true);
  await fetchData();
  setRefreshing(false);
};

<FlatList
  data={items}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  refreshing={refreshing}
  onRefresh={onRefresh}
/>

Using RefreshControl for Custom Styling

For more control over the spinner's appearance, use the refreshControl prop with a RefreshControl component. This lets you set the spinner's tintColor (iOS) and colors (Android), and even add a custom progressViewOffset for apps with fixed headers.

import { RefreshControl } from 'react-native';

<FlatList
  data={items}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  refreshControl={
    <RefreshControl
      refreshing={refreshing}
      onRefresh={onRefresh}
      tintColor='#6200ee'
      colors={['#6200ee', '#03dac5']}
    />
  }
/>

Infinite Scroll with onEndReached

Infinite scroll (load more / pagination) fetches additional data when the user approaches the bottom of the list. FlatList fires the onEndReached callback when the user scrolls within onEndReachedThreshold of the end. A threshold of 0.5 triggers the callback when the user is halfway to the end.

const [page, setPage] = useState(1);
const [items, setItems] = useState([]);

const loadMore = async () => {
  const newItems = await fetchPage(page + 1);
  setItems(prev => [...prev, ...newItems]);
  setPage(prev => prev + 1);
};

<FlatList
  data={items}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  onEndReached={loadMore}
  onEndReachedThreshold={0.5}
/>

Preventing Duplicate Load Calls

onEndReached can fire multiple times in quick succession as the user scrolls. Guard against duplicate fetches with a loading flag. Check the flag at the start of your load function and return early if a fetch is already in progress. Reset the flag once the data is loaded.

const [loadingMore, setLoadingMore] = useState(false);

const loadMore = async () => {
  if (loadingMore) return; // guard against duplicates
  setLoadingMore(true);
  const newItems = await fetchPage(page + 1);
  setItems(prev => [...prev, ...newItems]);
  setPage(prev => prev + 1);
  setLoadingMore(false);
};

Footer Spinner for Load More

Show an ActivityIndicator in the ListFooterComponent while the next page is loading. Hide it when all pages are loaded. This gives users a visual cue that more content is coming and prevents them from repeatedly scrolling to try to load more when it is already loading.

const renderFooter = () => {
  if (!loadingMore) return null;
  return <ActivityIndicator style={{ padding: 16 }} />;
};

<FlatList
  data={items}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  onEndReached={loadMore}
  onEndReachedThreshold={0.5}
  ListFooterComponent={renderFooter}
/>

Detecting End of Data

Keep a hasMore boolean in state. When your API returns fewer items than the page size, you know there are no more pages. Set hasMore to false and guard the loadMore function with this check. Also update the footer to show an 'End of list' message instead of a spinner.

const [hasMore, setHasMore] = useState(true);

const loadMore = async () => {
  if (loadingMore || !hasMore) return;
  setLoadingMore(true);
  const newItems = await fetchPage(page + 1);
  if (newItems.length < PAGE_SIZE) setHasMore(false);
  setItems(prev => [...prev, ...newItems]);
  setPage(prev => prev + 1);
  setLoadingMore(false);
};

Combining Refresh and Load More

Pull-to-refresh and load more can coexist in the same FlatList. On refresh, reset the page to 1, clear the existing items, fetch the first page, and reset hasMore to true. The two flows are independent and use separate loading states so they do not interfere with each other.

const onRefresh = async () => {
  setRefreshing(true);
  setPage(1);
  setHasMore(true);
  const freshData = await fetchPage(1);
  setItems(freshData);
  setRefreshing(false);
};

onEndReachedThreshold Best Practices

The onEndReachedThreshold value is a fraction of the visible list height, not a pixel value. Setting it to 0.2 triggers loading when 20% of the list content remains visible below the screen. A higher value starts loading earlier for slower APIs; a lower value is better for fast API responses.

// Trigger load more when 20% of list remains
<FlatList
  onEndReached={loadMore}
  onEndReachedThreshold={0.2}
/>

Scroll Position After Refresh

After a refresh replaces the data array, FlatList may retain the old scroll position, making the new content invisible. Call flatListRef.current.scrollToOffset({ offset: 0, animated: true }) after setting fresh data to bring the list back to the top for a polished user experience.

const flatListRef = useRef(null);

const onRefresh = async () => {
  setRefreshing(true);
  const freshData = await fetchPage(1);
  setItems(freshData);
  flatListRef.current?.scrollToOffset({ offset: 0, animated: true });
  setRefreshing(false);
};

Testing Pull-to-Refresh on Emulator

On iOS Simulator, pull-to-refresh works with a trackpad two-finger swipe down on the list. On Android Emulator, click and drag down from a list item. On a physical device, the gesture is natural. Always test both platforms because iOS uses a native spinner while Android uses its own Material-style indicator.

Quick Check

Test your understanding of pull-to-refresh and infinite scroll from this lesson.

Lesson Recap

In this lesson you learned: use the refreshing and onRefresh props to implement pull-to-refresh, use onEndReached with onEndReachedThreshold for infinite scroll, and guard loadMore with a loading flag to prevent duplicate API calls. Next up we explore SectionList for grouped data with headers.

Sıkça Sorulan Sorular

“Aşağı Çekerek Yenileme ve Daha Fazla Yükleme” dersi ücretsiz mi?

Evet — “Aşağı Çekerek Yenileme ve Daha Fazla Yükleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve React Native Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. React Native Academy kursu toplamda 4 dersten oluşur.

“Aşağı Çekerek Yenileme ve Daha Fazla Yükleme” dersinde ne öğreneceğim?

Kullanıcıların verileri yeniden yüklemek için aşağı çekmesine olanak tanımak üzere RefreshControl ile onRefresh uygulayın ve sonuçların sonraki sayfasını almak için onEndReached kullanın. React Native Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

React Native Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te React Native Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Aşağı Çekerek Yenileme ve Daha Fazla Yükleme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu React Native Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her React Native Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. FlatList Verileri, renderItem ve keyExtractor
  2. Aşağı Çekerek Yenileme ve Daha Fazla Yükleme
  3. Üst Bilgili SectionList
  4. Kişi Listesi Uygulaması Oluşturma
← React Native Academy Sayfasına Dön