-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59e60c2
commit bc7d59c
Showing
12 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Created by yuanguozheng on 16/1/22. | ||
*/ | ||
'use strict'; | ||
|
||
import React, { | ||
Component, | ||
View, | ||
Text, | ||
Image, | ||
TouchableWithoutFeedback, | ||
PropTypes, | ||
StyleSheet | ||
} from 'react-native'; | ||
|
||
export default class MenuButton extends React.Component { | ||
|
||
static propTypes = { | ||
renderIcon: PropTypes.number.isRequired, // 图片,加入.isRequired即为比填项 | ||
showText: PropTypes.string, // 显示标题\文字 | ||
tag: PropTypes.string, // Tag | ||
onClick: PropTypes.func // 回调函数 | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this._onClick = this._onClick.bind(this); // 需要在回调函数中使用this,必须使用bind(this)来绑定 | ||
} | ||
|
||
_onClick() { | ||
if (this.props.onClick) { // 在设置了回调函数的情况下 | ||
this.props.onClick(this.props.showText, this.props.tag); // 回调Title和Tag | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<TouchableWithoutFeedback onPress={this._onClick}> | ||
<View style={{alignItems:'center',flex:1}}> | ||
<Image style={styles.iconImg} source={this.props.renderIcon}/> | ||
<Text style={styles.showText}>{this.props.showText}</Text> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
iconImg: { | ||
width: 38, | ||
height: 38, | ||
marginBottom: 2 | ||
}, | ||
showText: { | ||
fontSize: 12 | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 comments
on commit bc7d59c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuanguozheng 这个 怎么破
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wdhonor 没太看懂是什么错误
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderIcon: PropTypes.number.isRequired,
showText: PropTypes.string,
tag: PropTypes.string
onClick: PropTypes.func
這裏應該在proptypes前加上react.
renderIcon: React.PropTypes.number.isRequired,
showText: React.PropTypes.string,
tag: React.PropTypes.string,
onClick: React.PropTypes.func,
上面的undefined is not an object就是這個問題
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HuangQiii 从react包import一下就可以了
This comment has been minimized.
Sorry, something went wrong.
TrickhanApr 28, 2017
This comment has been minimized.
Sorry, something went wrong.
yuanguozhengMay 4, 2017
Author Owner???
This comment has been minimized.
Sorry, something went wrong.
yuanguozhengMay 4, 2017
Author Owner@Trickhan