Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing refresh icon while unmounting a screen in Android. #34718

Open
rifad4u opened this issue Sep 18, 2022 · 15 comments
Open

Showing refresh icon while unmounting a screen in Android. #34718

rifad4u opened this issue Sep 18, 2022 · 15 comments
Labels
Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale Platform: Android Android applications.

Comments

@rifad4u
Copy link

rifad4u commented Sep 18, 2022

Description

If a component have refresh control or flatlist with refreshing and onrefresh props , then showing white circle on the top of the screen while navigating back. if i disable refresh control or remove the onrefresh and refreshing prop from flatlist then this white circle won’t come while navigating back.

Version

0.70.0

Output of npx react-native info

System:
OS: macOS 12.6
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 25.20 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.19.0 - /usr/local/opt/node@14/bin/node
Yarn: Not Found
npm: 6.14.16 - /usr/local/opt/node@14/bin/npm
Watchman: 2022.02.07.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8815526
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.0 => 0.70.0
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

I have attached the sample code here , run the same in any android device . while navigating back from the profile screen it showing a white circle on the top just below the header bar.

Please give me a solution for the same.
Thanks

Snack, code example, screenshot, or link to a repository

import * as React from 'react';
import { Button, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, backgroundColor : "black" ,alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Go to Profile"
onPress={() => navigation.navigate('Profile')}
/>

);
}

import { SafeAreaView, FlatList, StyleSheet, Text, StatusBar } from 'react-native';

const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];

const Item = ({ title }) => (

{title}

);

const ProfileScreen = () => {
const renderItem = ({ item }) => (

);

return (

<Text style={{color : 'white' , alignSelf : 'center'}}>Heading
<FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
onRefresh={()=>{}}
refreshing={false}
/>

);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor : 'black'
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
});

const Stack = createNativeStackNavigator();

function MyStack() {
return (
<Stack.Navigator
screenOptions={{
animation : "slide_from_right",
}}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
</Stack.Navigator>
);
}

export default function App() {
return (



);
}

Screenshot 2022-09-18 at 7 54 30 PM

@gabrieldonadel
Copy link
Collaborator

I've also been experiencing this on version 0.68.2

@rifad4u
Copy link
Author

rifad4u commented Oct 18, 2022

I've also been experiencing this on version 0.68.2

Have u got any solution for the same?

@PedroBern
Copy link

PedroBern commented Oct 29, 2022

Same issue in 0.69.6

Quick workaround if you are using react navigation

note: this is just a workaround. Not a fix. This issue should be fixed upstream.

The workaround below works for my use case.

const selectHook = <T>({ useIos, useAndroid }: { useIos: T; useAndroid: T }) => {
  return Platform.select({
    default: useIos,
    android: useAndroid,
  })
}

/**
 * Quick workaround for refreshing issue on Android:
 * The refresh control is showing up above the header when unmounting the screen.
 * Note: It's happening when using a custom header component, but I haven't tried using
 * the native header from the native stack.
 */
const useProgressViewOffset = selectHook({
  useAndroid: () => {
    const navigation = useNavigation()
    const [progressViewOffset, setProgressViewOffset] = useState<undefined | number>(undefined)
    const goBackEventWasHandled = useRef(false)

    // prevent the navigation event and hide the refresh indicator
    useEffect(() => {
      const unsubscribe = navigation.addListener('beforeRemove', (event) => {
        // Handle GO_BACK event only, because it fits my use case, please tweak it to fit yours
        if (event.data.action.type === 'GO_BACK' && !goBackEventWasHandled.current) {
          event.preventDefault()
          goBackEventWasHandled.current = true
          setProgressViewOffset(-1000) // set to a ridiculous value to hide the refresh control
        }
      })

      return unsubscribe
    }, [navigation])

    // perform the navigation with the hidden refresh indicator
    useEffect(() => {
      if (progressViewOffset !== undefined) {
        navigation.goBack()
      }
    }, [navigation, progressViewOffset])

    return progressViewOffset
  },
  useIos: () => undefined,
})

Usage

// ...
const progressViewOffset = useProgressViewOffset()
// ...
<RefreshControl
  {...refreshProps}
  progressViewOffset={progressViewOffset}
/>

@pierroo
Copy link

pierroo commented Jan 25, 2023

It's been a while, is there any news about this issue?

Although, might sound silly but is there any sort of performance impact when adding these refreshProps?

@hakanpinar
Copy link

Same problem here.. (version 0.70.5)

@mickdewald
Copy link

Can confirm the same issue in v0.71.7

@novirusallowed
Copy link

novirusallowed commented Jun 1, 2023

Can confirm the same issue in v0.71.7

Same for me. But noticed that it doesn't happen anymore after you interact with it once.

@PedroBern
Copy link

That's true. But still, it's ugly that it appears if you don't interact.
For instance, I had to use a helper in my FlatList to prevent it

@micktg is there any difference compared to #34718 (comment)?

@mickdewald
Copy link

mickdewald commented Jun 2, 2023

That's true. But still, it's ugly that it appears if you don't interact.
For instance, I had to use a helper in my FlatList to prevent it

@micktg is there any difference compared to #34718 (comment)?

Oh excuse me. My fault.
I didn't scroll up for the last answer.
This is of course exactly the same.
I even got the link as a reference to this ticket here in the comments.

@Haseebshah936
Copy link

Facing the same issue @PedroBern for my use case the solution did not worked. The main point is that this issue needs to be fixed by the core team. As FlatlList is a core component so it should not be behaving in such a manner.

Copy link

github-actions bot commented May 6, 2024

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 6, 2024
@lucasbasquerotto
Copy link

not stale

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label May 7, 2024
@react-native-bot
Copy link
Collaborator

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 3, 2024
@rifad4u
Copy link
Author

rifad4u commented Nov 3, 2024

Not stale

@react-native-bot react-native-bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 4, 2024
@cortinico cortinico added the Never gets stale Prevent those issues and PRs from getting stale label Nov 4, 2024
@CanePro612
Copy link

put progressViewOffset={-1} and it will fix the issue. It has done it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale Platform: Android Android applications.
Projects
None yet
Development

No branches or pull requests