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

View height regression caused by pagingEnabled wrapper div #1299

Open
brunolemos opened this issue Mar 20, 2019 · 3 comments
Open

View height regression caused by pagingEnabled wrapper div #1299

brunolemos opened this issue Mar 20, 2019 · 3 comments
Labels
project:react-native-web Issue associated with react-native-web

Comments

@brunolemos
Copy link
Contributor

As first reported here, I investigated and got to the root cause.

The problem

Regression introduced when upgrading from 0.9.9 to 0.10.0+:

Before (correct) After (wrong)
devhub 3 devhub 1

How to reproduce
https://codesandbox.io/s/lyv4oywmv9?fontsize=14

It seems there is a new div wrap when using pagingEnabled and since it doesn't have a full height this happens.

Steps to reproduce:

  1. <FlatList horizontal pagingEnabled ... />
  2. renderItem with <View style={{ height: '100%' }} ... />
  3. Works on 0.9.9, breaks on 0.10.0

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.11.1
  • React (version): 16.8.4
  • Browser: Chrome latest
@brunolemos
Copy link
Contributor Author

brunolemos commented Mar 20, 2019

Workaround I'm currently using:

return (
  <FlatList
    ref={flatListRef}
    data-paging-enabled-fix
    ...
  />
)
[data-paging-enabled-fix]  > div > div > div {
  height: 100%;
}

@necolas necolas added this to the 0.11.x milestone Apr 5, 2019
@necolas necolas removed this from the 0.11.x milestone Oct 7, 2019
@petrbela
Copy link
Contributor

petrbela commented Oct 4, 2020

Note that in RNW >=0.13:

Forwarding of data-* props is no longer supported. Use dataSet instead. For example, dataSet={{ someName: 1 }}

So to achieve the hotfix with the css provided above, you can use:

return (
  <FlatList
    dataSet={{ 'paging-enabled-fix': true }}
    ...
  />
)

Here's the specific implementation:

// dataSet
if (dataSet != null) {
for (const prop in dataSet) {
if (hasOwnProperty.call(dataSet, prop)) {
const value = dataSet[prop];
if (value != null) {
domProps[`data-${prop}`] = value;
}
}
}
}

@nandorojo
Copy link
Contributor

Just confirming that I'm getting this with RNW 0.14.2. @brunolemos thanks for posting your solution.

For anyone using this with Next.js (+ Expo), this is my solution (with styled-jsx, native to Next.js):

<View sx={{ flex: 1 }} onLayout={onLayout}>
  <Animated.FlatList
    data={images}
    ref={flatlist}
    keyExtractor={(item) => item.url}
    renderItem={({ item }) => <ImageCarouselItem height={height} image={item} width={width} />}
    extraData={{ width }}
    onScroll={event(
      [
        {
          nativeEvent: {
            contentOffset: { x: scrollX }
          }
        }
      ],
      {
        useNativeDriver
      }
    )}
    // @ts-ignore
    dataSet={{ 'paging-enabled-fix': true }}
    pagingEnabled
    horizontal
    getItemLayout={(_, index) => {
      return {
        length: width,
        offset: width * index,
        index
      }
    }}
    // viewabilityConfig={viewabilityConfig}
  />
  {Platform.OS === 'web' && (
    <style jsx>{`
      [data-paging-enabled-fix] > div > div > div {
        height: 100%;
      }
    `}</style>
  )}
</View>

@necolas necolas added this to the 0.15 milestone Oct 27, 2020
@necolas necolas removed this from the 0.15 milestone Dec 8, 2020
@necolas necolas added the project:react-native-web Issue associated with react-native-web label Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

4 participants