您的位置:首页 > Web前端 > React

React Native android 按钮的波纹效果

2016-08-19 11:21 573 查看


TouchableNativeFeedback 

A wrapper for making views respond properly to touches (Android only). On Android this component uses native state drawable to display touch feedback. At the moment it only supports having a single View instance as a child node, as it's implemented by replacing
that View with another instance of RCTView node with some additional properties set.

Background drawable of native feedback touchable can be customized with 
background
property.

Example:

renderButton:

function()
{

return
( <TouchableNativeFeedback onPress={this._onPressButton}
background={TouchableNativeFeedback.SelectableBackground()}>
<View style={{width:

150, height:

100, backgroundColor:

'red'}}>
<Text style={{margin:

30}}>Button</Text>
</View> </TouchableNativeFeedback>
);},


Props 


TouchableWithoutFeedback
props... 


background backgroundPropType 

Determines the type of background drawable that's going to be used to display feedback. It takes an object with 
type
 property and extra data depending on the 
type
.
It's recommended to use one of the static methods to generate that dictionary.


Methods 


static SelectableBackground(0) 

Creates an object that represents android theme's default background for selectable elements (?android:attr/selectableItemBackground).


static SelectableBackgroundBorderless(0) 

Creates an object that represent android theme's default background for borderless selectable elements (?android:attr/selectableItemBackgroundBorderless). Available on android API level 21+.


static Ripple(color,
borderless) 

Creates an object that represents ripple drawable with specified color (as a string). If property 
borderless
 evaluates to true the ripple will render outside of the view bounds
(see native actionbar buttons as an example of that behavior). This background type is available on Android API level 21+.

Parameters:
Name and TypeDescription
color

string
The ripple color

borderless

boolean
If the ripple can render outside it's bounds

<Button
background={ (Platform.OS === 'android') ? TouchableNativeFeedback.Ripple('#f39c12', true) : null }
style={ styles.buttonStyle }
textStyle={ styles.textStyle }
onPress={ () => {
console.log('world!')
} }>
Hello
</Button>


检测平台如果是Android平台,就设置波纹效果

background={ (Platform.OS === 'android') ? TouchableNativeFeedback.Ripple('#f39c12', true) : null }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: