nativescript-ripple

我要开发同款
匿名用户2021年11月23日
55阅读
开发技术Java
所属分类AndroidUI组件、手机/移动开发、Android UI 组件
授权协议Apache-2.0 License

作品详情

Nativescript-Ripple

Thispluginaimstobringanative(orclosetonative)rippleimplementationonAndroidandiOS.TheandroidversionusesaRippleDrawableandconservesthepreviousbackground,aswellasCSSstyles.

Installationtnspluginaddnativescript-rippleUsage

ThiswillonlyworkonAndroidLollipop5.0orlaterandanyversionofiOS.

XML

ENSURETOBINDATAPLISTENERTOTHECHILDELEMENT,ORTHISWON'TWORKONANDROID

<Pageclass="page"navigatingTo="onNavigatingTo"xmlns="https://schemas.nativescript.org/tns.xsd"xmlns:RL="nativescript-ripple"><ActionBarclass="action-bar"><Labelclass="action-bar-title"text="Home"></Label></ActionBar><ScrollView><StackLayout><RL:RipplerippleColor="#d50000"><Labeltext="RedRipples!!!"class="message"textWrap="true"tap="dummy"/></RL:Ripple><RL:RipplerippleColor="#fff000"><Imagesrc="~/home/images/batman.png"margin="10"stretch="aspectFit"tap="dummy"/></RL:Ripple><RL:Ripple><Labeltext="DefaultRipple"class="message"textWrap="true"tap="dummy"/></RL:Ripple><RL:RipplerippleColor="#fff"><GridLayoutbackgroundColor="#FF4081"borderRadius="30"height="60"width="60"tap="dummy"><Labeltext="B"fontSize="30"color="#fff"verticalAlignment="center"horizontalAlignment="center"textWrap="true"/></GridLayout></RL:Ripple><RL:RipplerippleColor="#c8c8c8"><Labelclass="label-button"text="LighterRipple"textWrap="true"tap="dummy"/></RL:Ripple><RL:RipplerippleColor="#f5f5f5"><Labeltext="Possibilities"color="#fff"padding="10"textWrap="true"tap="tapEvent"class="dark-button"/></RL:Ripple></StackLayout></ScrollView></Page>RippleOptions

rippleColorsetstheripplecolor.Examples:"#ffffff"|"rgba(255,255,255,0.5)".

rippleColorAlphasetstheripplecoloralpha(multiplicative).Default:0.25.NOTE:Thisismultiplicativetoa0.5alphagivenbythenativeclassRippleDrawable.ThissamevalueishardcodediniOStomakebothplatformsbehavethesame.

rippleLayersetsthelayertherippleisappliedto(ANDROIDONLY).Allowedvalues:foreground(defaultonAPI>=23)|background.SettingthistobackgroundwillmaketherippleonlyappearontheView'sbackground(meaningitwon'tappearinfrontofanimage,forexample).

rippleEnabledcanbesetto"false"(rippleEnabled="false")todisabletheripple.ThiswillalsodisablerippleeffectsonViewsthathavethemnatively(likeButton).

AngularImporttheNgRippleModule

Ifyou'reusingothermodulesthatchangethebackground(likehttps://github.com/Especializa/nativescript-ng-shadow),ensuretoimportitLAST,otherwisetheRipplebackgroundwillbeoverwritten.

import{NgRippleModule}from'nativescript-ripple/angular';@NgModule({imports:[NgRippleModule,//...],//...})exportclassMyModule{}Useitinthetemplates:

ENSURETOBINDATAPLISTENER,ORTHISWON'TWORKONANDROID

<Labelrippletext="mylabeltext"(tap)="tapfn()"></Label>

<StackLayoutripplerippleColor="#00ff00"style="padding:30;border-radius:10;"(tap)="tapfn()"><Labeltext="thisisinsidethelayout!"></Label></StackLayout>Implementationdetails

OnAndroid,iftheviewdoesnothaveabackground,weassignatransparentone.Otherwise,turningthescreenoffandthenonagainmakesthebackgroundthesameasthemaskcolor(black).

RippleOptions

rippleColorsetstheripplecolor.Examples:"#ffffff"|"rgba(255,255,255,0.5)".

rippleColorAlphasetstheripplecoloralpha(multiplicative).Default:0.25.NOTE:Thisismultiplicativetoa0.5alphagivenbythenativeclassRippleDrawable.ThissamevalueishardcodediniOStomakebothplatformsbehavethesame.

rippleLayersetsthelayertherippleisappliedto(ANDROIDONLY).Allowedvalues:foreground(defaultonAPI>=23)|background.SettingthistobackgroundwillmaketherippleonlyappearontheView'sbackground(meaningitwon'tappearinfrontofanimage,forexample).

ripplecanbesetto"off"(ripple="off")todisabletheripple.ThiswillalsodisablerippleeffectsonViewsthathavethemnatively(likeButton).

KnownIssuesNoRippleonAndroid

IfyourRippleisnotworkingonAndroid,trythefollowing:

Verifytheviewyou'reapplyingtheRippletohasatapeventIftheviewisaText-likeview(Buttons,Labels,etc),thereisabugthatpreventsanyforegroundtobeappliedtoitwhentextWrapisnottrueandtextAlignmentiscenterorright.Therearemanyfixes(onlyoneisneeded):WraptheViewinanotherlayout(likeaGridLayout)ChangetherippleLayertobackgroundUsetextWrap="true"DisableHorizontallyScrollingforyourView(yourLabel.android.setHorizontallyScrolling(false);).Warning:thisissettotrueeverytimetextAlignmentchangesLicense

ApacheLicenseVersion2.0,January2004

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论