react / react/react-native

Animated.FlatList doesn't bounce back during refreshing if calling Alert.alert in `onRefresh`

Open
#49,052 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

API: Alert API: Animated Component: FlatList Issue: Author Provided Repro
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

Description

I attempt to add a alert popup box when user refreshes the FlatList, but it seems that Alert.alert will interfere with Animated.FlatList's animation and will cause it doesn't bounce back

Steps to reproduce

Minimal code to reproduce:

import { Animated, StyleSheet, Alert, Dimensions } from 'react-native';

import { View, Text } from 'react-native';

function App() {
  return (
    <Animated.FlatList
        data={["item1", "item2", "item3"]}
        renderItem={({ item }) => <Text style={{fontSize: 20, margin: 10, padding: 10}}>{item}</Text>}
        style={{ position: "relative", borderColor: "black", margin: 10, padding: 10, borderWidth: 1, borderRadius: 10 }}
        refreshing={false}
        onRefresh={() => {
          Alert.alert(
            "Alert",
            "Sure?",
            [
              {text: "cancel", style: "cancel", onPress: () => {}},
              {
                text: "ok",
                onPress: () => {
                  console.log("ok");
                },
              },
            ],
          );
        }}
      />
  );
}

const { width, height } = Dimensions.get('window');


export default function HomeScreen() {
  return (
    <View style={styles.container}>
      <View style={[styles.box, {
        position: 'absolute',
        top: height*0.25,
        left: width*0.25,
      }]}>
        <App />
      </View>
  </View>

  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
  },
  box: {
    // backgroundColor: 'blue',
    opacity: 0.5,
  },
  titleContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: 8,
  },
  stepContainer: {
    gap: 8,
    marginBottom: 8,
  },
  reactLogo: {
    height: 178,
    width: 290,
    bottom: 0,
    left: 0,
    position: 'absolute',
  },
});

React Native Version

0.76.6

Affected Platforms

Runtime - iOS

Output of npx react-native info
(base) ➜  my-app git:(main) ✗ npx react-native info

⚠️ react-native depends on @react-native-community/cli for cli commands. To fix update your package.json to include:


  "devDependencies": {
    "@react-native-community/cli": "latest",
  }
Stacktrace or Logs
There's no crash so I don't think log will be useful
Reproducer

https://snack.expo.dev/r96AruoARFS859F2IPwRx

Screenshots and Videos

It's easy to see it using the reproducer link and select iOS runtime. Just swipe down and refresh the list and you'll see it

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Snack reproducer and run it on the iOS runtime, focusing on Animated.FlatList's onRefresh behavior when it calls Alert.alert. Confirm the list fails to bounce back after the alert appears, and consider the issue done when refreshing with the alert restores the expected bounce-back animation.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.