Guest User

Untitled

a guest
Nov 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. const dataArray = [{key: 0,id: 'A',},{key: 1,id: 'B',},{key: 2,id: 'Z',}]
  2.  
  3. // Root Component
  4. export default class App extends Component {
  5. render(){
  6. return (
  7. <View>
  8. {this.getSomeText()}
  9. </
  10. getSomeText() {
  11. return dataArray.map( d =>
  12. <SomeText key={d.key} id={d.id} onLayout={(e) => this.onLayout(e)} />
  13. )
  14. }
  15. onLayout (e, id ) {
  16. // add these items to array
  17. // e.nativeEvent.Layout{Width,Height,x,y,id}
  18. // I can add the e data but the id data never comes through.
  19. }
  20. }
  21.  
  22.  
  23. // Child Component
  24. class SomeText extends Component {
  25. render() {
  26. return (
  27. <Text
  28. onLayout={this.props.onLayout}
  29. // onLayout as above this returns the event e but
  30. // 2. this.props.onLayout() // doesn't return e at all ??
  31. // 3. () => this.props.onLayout // doesn't work either, why?
  32. // 4. (e, this.props.key) => this.props.onLayout(this.props.key)
  33. // 4 doesnt work either
  34. >Some text</Text>
  35. )
  36. }
  37. }
Add Comment
Please, Sign In to add comment