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

Not working with flat list #6

Open
TommyTheTribe opened this issue Apr 14, 2023 · 4 comments
Open

Not working with flat list #6

TommyTheTribe opened this issue Apr 14, 2023 · 4 comments

Comments

@TommyTheTribe
Copy link

TommyTheTribe commented Apr 14, 2023

Hi sir, thanks for your work !

It seems that there is an issue with FlatList, I got an error ref.measureLayout must be called with a node handle or a ref to a native component.

Here is my code :

import {FlatList, ScrollTo, Target} from '@nandorojo/anchor';
import {Text, View} from 'react-native';

const test = [1, 2, 3, 4, 5, 6, 7, 8];

  return (
    <View style={{flex: 1}}>
      <FlatList
        data={test}
        renderItem={({item, index}) => {
          if (index === 0) {
            return (
              <ScrollTo target="bottom-content">
                <Text>Scroll to bottom content</Text>
              </ScrollTo>
            );
          }
          if (index === test.length - 1) {
            return (
              <Target name="bottom-content">
                <View style={{height: 100, backgroundColor: 'blue'}} />
              </Target>
            );
          }
          return <View style={{height: 100, backgroundColor: 'blue'}} />;
        }}
      />
    </View>
  );

"react-native": "0.71.0"

Thanks for your help !

@stefanahman
Copy link

After a lot of testing I managed to solve this by calling getNativeScrollRef on FlatList<T>:

import {FlatList, ScrollView} from 'react-native-gesture-handler'
import {useRegisterScroller} from '@nandorojo/anchor'

const {registerScrollRef} = useRegisterScroller()

<FlatList
  ref={list => registerScrollRef(list?.getNativeScrollRef() as ScrollView)}
  // ...
/>

@nandorojo
Copy link
Owner

Hmm interesting we could implement this in the library

@yu1iaw
Copy link

yu1iaw commented May 20, 2024

It would be great, if I could achieve the same result with SectionList

@lee1409
Copy link

lee1409 commented Jul 29, 2024

I'm curious if the anchoring logic still works when the list item has not yet been rendered by the FlatList? Does anyone face this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants