微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React Native android 按钮的波纹效果

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 withbackgroundproperty.

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

backgroundbackgroundPropType

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

Methods

staticSelectableBackground(0)

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

staticSelectableBackgroundBorderless(0)

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

staticRipple(color,borderless)

Creates an object that represents ripple drawable with specified color (as a string). If propertyborderlessevaluates 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 Type Description
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 }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐