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

Support pagingEnabled property by CSS child selector #2739

Open
1 task done
ArrayZoneYour opened this issue Nov 27, 2024 · 0 comments
Open
1 task done

Support pagingEnabled property by CSS child selector #2739

ArrayZoneYour opened this issue Nov 27, 2024 · 0 comments
Labels
enhancement Requires extension or creation of new React Native API

Comments

@ArrayZoneYour
Copy link

Is there an existing request?

  • I have searched for this request

Describe the feature request

pagingEnabled has been implemented #1212 by wrapping original children with pagingEnabledChild style

const children =
      hasStickyHeaderIndices || pagingEnabled
        ? React.Children.map(this.props.children, (child, i) => {
            const isSticky =
              hasStickyHeaderIndices && stickyHeaderIndices.indexOf(i) > -1;
            if (child != null && (isSticky || pagingEnabled)) {
              return (
                <View
                  style={[
                    isSticky && styles.stickyHeader,
                    pagingEnabled && styles.pagingEnabledChild
                  ]}
                >
                  {child}
                </View>
              );
            } else {
              return child;
            }
          })
        : this.props.children;

It only works when children is directly written in ScrollView.

Supported

<ScrollView horizontal style={{ width: Dimensions.get('window').width }} pagingEnabled>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 0</Text>
    </View>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 1</Text>
    </View>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 2</Text>
    </View>
</ScrollView>

Unsupported

const Children = () => (
  <>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 0</Text>
    </View>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 1</Text>
    </View>
    <View style={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}>
      <Text>Page 2</Text>
    </View>
  </>
)

<ScrollView horizontal style={{ width: Dimensions.get('window').width }} pagingEnable>
    <Children />
</ScrollView>

According to W3C spec (https://www.w3.org/TR/css-scroll-snap-1/), we only need to set scroll-snap-type style to ScrollView element and scroll-snap-align style to child elements. It's more easier with CSS selector as follows:

<ScrollView horizontal style={{ width: Dimensions.get('window').width }} testID="paging-enable-x">
    <Children />
</ScrollView>
[data-testid='paging-enable-x'] {
  scroll-snap-type: x mandatory;
}

/* internal div is generated by `contentContainer` in `ScrollView#render()` */
[data-testid='paging-enable-x'] > div > div {
  scroll-snap-align: start;
}

Currently, I only found style generation from https://github.com/necolas/styleq and React JSX inline style, will it acceptable to involve css selector to archive some native features like pagingEnable / snapToInterval / snapToAlignment ?

@ArrayZoneYour ArrayZoneYour added the enhancement Requires extension or creation of new React Native API label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requires extension or creation of new React Native API
Projects
None yet
Development

No branches or pull requests

1 participant