React Native android 按钮的波纹效果

前端之家收集整理的这篇文章主要介绍了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 }

原文链接:https://www.f2er.com/react/306191.html

猜你在找的React相关文章