import { dynamicElevationOffsetProperty , elevationProperty , rippleColorProperty , shapeProperty , themer } from '@nativescript-community/ui-material-core' ; import { createStateListAnimator , getColorStateList , isPostLollipop } from '@nativescript-community/ui-material-core/android/utils' ; import { Background , Color , ImageSource , Length , backgroundInternalProperty , colorProperty } from '@nativescript/core' ; import { textProperty } from '@nativescript/core/ui/text-base' ; import { FloatingActionButtonBase , expandedProperty , imageSourceProperty , sizeProperty , srcProperty } from './floatingactionbutton-common' ; let MDCFabButton ; export class FloatingActionButton extends FloatingActionButtonBase { nativeViewProtected : com . google . android . material . floatingactionbutton . ExtendedFloatingActionButton ; defaultPadding : number ; public createNativeView ( ) { if ( ! MDCFabButton ) { MDCFabButton = com . google . android . material . floatingactionbutton . ExtendedFloatingActionButton ; } const view = new MDCFabButton ( this . _context ) ; this . defaultPadding = view . getPaddingTop ( ) ; return view ; } [ imageSourceProperty . setNative ] ( value ) { const nativeView = this . nativeViewProtected ; if ( value && value . android ) { nativeView . setIcon ( new android . graphics . drawable . BitmapDrawable ( value . android ) ) ; } else { nativeView . setIcon ( null ) ; } } [ srcProperty . setNative ] ( value ) { this . _createImageSourceFromSrc ( value ) ; } public show ( ) { this . nativeView . show ( ) ; } public hide ( ) { this . nativeView . hide ( ) ; } createStateListAnimatorTimeout ; createStateListAnimator ( ) { if ( ! this . createStateListAnimatorTimeout ) { this . createStateListAnimatorTimeout = setTimeout ( ( ) => { this . createStateListAnimatorTimeout = null ; createStateListAnimator ( this , this . nativeViewProtected ) ; } ) ; } } [ elevationProperty . setNative ] ( value ) { if ( isPostLollipop ( ) ) { this . createStateListAnimator ( ) ; } else { const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ; androidx . core . view . ViewCompat . setElevation ( this . nativeViewProtected , newValue ) ; } } [ dynamicElevationOffsetProperty . setNative ] ( value ) { if ( isPostLollipop ( ) ) { this . createStateListAnimator ( ) ; } else { const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ; androidx . core . view . ViewCompat . setTranslationZ ( this . nativeViewProtected , newValue ) ; } } [ textProperty . setNative ] ( value ) { this . nativeViewProtected . setText ( value ) ; } [ sizeProperty . setNative ] ( value ) { switch ( value ) { case 'mini' : this . nativeViewProtected . setPadding ( 30 , 30 , 30 , 30 ) ; break ; case 'auto' : default : this . nativeViewProtected . setPadding ( this . defaultPadding , this . defaultPadding , this . defaultPadding , this . defaultPadding ) ; break ; } } [ backgroundInternalProperty . setNative ] ( value ) { if ( this . nativeViewProtected ) { if ( value instanceof android . graphics . drawable . Drawable ) { this . nativeViewProtected . setBackgroundDrawable ( value ) ; } else { if ( value . color ) { this . nativeViewProtected . setBackgroundTintList ( getColorStateList ( value . color . android ) ) ; } } } } [ colorProperty . setNative ] ( value ) { const color = ! value || value instanceof Color ? value : new Color ( value ) ; this . nativeViewProtected . setIconTint ( getColorStateList ( color . android ) ) ; } [ rippleColorProperty . setNative ] ( value ) { const color = ! value || value instanceof Color ? value : new Color ( value ) ; this . nativeViewProtected . setRippleColor ( getColorStateList ( color . android ) ) ; } [ rippleColorProperty . setNative ] ( value ) { const color = ! value || value instanceof Color ? value : new Color ( value ) ; this . nativeViewProtected . setRippleColor ( getColorStateList ( color . android ) ) ; } [ expandedProperty . setNative ] ( value ) { if ( value ) { this . nativeViewProtected . extend ( ) ; } else { this . nativeViewProtected . shrink ( ) ; } } defaultAppearanceModel ; [ shapeProperty . setNative ] ( shape ) { const appearanceModel = themer . getShape ( shape ) ; if ( ! shape ) { if ( this . defaultAppearanceModel ) { this . nativeViewProtected . setShapeAppearanceModel ( this . defaultAppearanceModel ) ; } } else { if ( ! this . defaultAppearanceModel ) { this . defaultAppearanceModel = this . nativeViewProtected . getShapeAppearanceModel ( ) ; } this . nativeViewProtected . setShapeAppearanceModel ( appearanceModel ) ; } } }