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

Adding renderHeader prop to component #31

Open
luisfuertes opened this issue Sep 14, 2017 · 1 comment
Open

Adding renderHeader prop to component #31

luisfuertes opened this issue Sep 14, 2017 · 1 comment

Comments

@luisfuertes
Copy link

luisfuertes commented Sep 14, 2017

I am trying to add renderHeader prop in component like a ListView and have the posibility of drag items over the header.

I download the component code and in index.js and in render have added:

  • { this.props.renderHeader && this.props.renderHeader() }
  • And important add style={{flex: 1}} to SortableGrid props.
class SortableGrid extends Component {

    render = () =>
      <Animated.View
        style={ this._getGridStyle() }
        onLayout={ this.assessGridSize }
      >

        { this.props.renderHeader && this.props.renderHeader() }

        { this.state.gridLayout &&
          this.items.map( (item, key) =>
            <Block
              key = { key }
              style = { this._getBlockStyle(key) }
              onLayout = { this.saveBlockPositions(key) }
              panHandlers = { this._panResponder.panHandlers }
              delayLongPress = { this.dragActivationTreshold }
              onLongPress = { this.activateDrag(key) }
              onPress = { this.handleTap(item.props) }
              itemWrapperStyle = { this._getItemWrapperStyle(key) }
              deletionView = { this._getDeletionView(key) }
            >
              {item}
            </Block>
        )}
      </Animated.View>

      ....
}

With that all works fine. But the problem is when i wrap SortableGrid in a ScrollView, because the first render all works fine but after scroll, component re-render and break the ScrollView cutting end elements.

MyScreen code:

     return (
      <ScrollView scrollEnabled={this.state.scrollEnabled}>

        <SortableGrid
          style={{flex: 1}}
          dragActivationTreshold={50}
          onDragStart={ () => this.onDragStart() }
          onDragRelease={ () => this.onDragRelease() }
          renderHeader={ () => this.renderHeader() }
        >
          {
            _.map(data, (item, index) => {
              return this.renderItem(item, index)
            })
          }
        </SortableGrid>

      </ScrollView>
    )

@ollija can you help me with this? If all works fine i could do PR

@luisfuertes
Copy link
Author

luisfuertes commented Sep 14, 2017

Ok i fix it adding on component index.js:

this.state = {
   ...
  headerHeight: 0,
}

_animateGridHeight = () => {
    this.gridHeightTarget = this.props.renderHeader ? (this.rows * this.state.blockWidth) + 
    this.state.headerHeight + this.state.blockWidth : this.rows * this.state.blockWidth
    ....
}

    render = () =>
        <Animated.View
          style={ this._getGridStyle() }
          onLayout={ this.assessGridSize }
        >

          <View onLayout={ (e) => this.setState({ headerHeight: e.nativeEvent.layout.height }) }>
            { this.props.renderHeader && this.props.renderHeader() }
          </View>

         ....

        </Animated.View>

But on first render it do extrain effect, im working on it. And now i need add ScrollView only to grid elements, and fix header on top

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

1 participant