-
Notifications
You must be signed in to change notification settings - Fork 25k
Closed
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
I packaged a component, import the component,dynamic loop creation DOM , Passing a callback function as the component property,In packaged component, the property is undefined,I use the method is wrong?
in AnimateImage.js
This line of code is wrong
// print undefined, If don't create DOM dynamically, this property can be obtained.
console.log(onPress, 'onPress');
Game.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
TouchableWithoutFeedback,
Text,
View
} from 'react-native';
import AnimateImage from '../control/AnimateImage';
import _ from 'lodash';
export default class Game extends Component {
constructor(props){
super(props);
let {imageArray} = this.props;
this.state = {
rows: [],
imageArray: imageArray || [],
};
};
componentDidMount(){
this.createPokers();
};
onPress = () => {
console.log('sucess');
}
//imageArray = [1,2,3,4]
createPokers = () => {
let self = this;
let rows = imageArray.reduce(function(memo, value){
memo.push(
<AnimateImage
key={'backImage'+ value}
style={{left: 0 - value * 120}}
animate="bounceInLeft"
imageHeight={220}
imageWidth={150}>
onPress={self.onPress}
</AnimateImage>
);
return memo;
}, []);
this.setState({rows: rows});
};
render() {
return (
<View>
<View ref="viewPoker" style={[styles.viewRow, styles.AnimateImage]}>
{this.state.rows}
</View>
</View>
);
}
}
const styles = StyleSheet.create({
viewRow: {
flexDirection: 'row',
position: 'absolute',
},
AnimateImage: {
left: 150,
top:300,
}
});
AppRegistry.registerComponent('Game', () => Game);
AnimateImage.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Image,
TouchableWithoutFeedback,
Text,
View
} from 'react-native';
import * as Animatable from 'react-native-animatable';
export default class AnimateImage extends Component {
constructor(props){
super(props);
let {animate, text, imageHeight, imageWidth, style, onPress} = this.props;
console.log(onPress, 'onPress'); // print undefined
this.state = {
animate: animate || '',
imageHeight: imageHeight || 300,
imageWidth: imageWidth || 200,
style: style || {},
callback: onPress || {}
};
};
buttonPress = () => {
this.refs.view.fadeOutUpBig(1500).then((endState) => {
this.state.callback();
});
};
render() {
return (
<TouchableWithoutFeedback onPress={this.buttonPress}>
<Animatable.View animation={this.state.animate} ref="view">
<Image
style={[this.state.style, {height: parseInt(this.state.imageHeight), width:parseInt(this.state.imageWidth)}]}
source={require('./../../src/images/poker-back.png')}
/>
</Animatable.View>
</TouchableWithoutFeedback>
);
}
}
AppRegistry.registerComponent('AnimateImage', () => AnimateImage);
Metadata
Metadata
Assignees
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.