-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
295 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import { LikeButton } from '@candies/like_button'; | ||
import { LikeButton, like_button } from '@candies/like_button'; | ||
|
||
@Entry | ||
@Component | ||
struct Index { | ||
@State message: string = 'Hello World'; | ||
@State controller: like_button.Controller = new like_button.Controller(); | ||
|
||
aboutToAppear() { | ||
// this.controller.likeComponentSize = 150; | ||
// this.controller.animationDuration=1000; | ||
} | ||
|
||
build() { | ||
Row() { | ||
Column() { | ||
Text(this.message) | ||
.fontSize(50) | ||
.fontWeight(FontWeight.Bold) | ||
LikeButton( | ||
{ animationDuration: 5000, isLiked: false, } | ||
) | ||
.backgroundColor('#FFFF5722') | ||
Navigation(){ | ||
Grid() { | ||
GridItem() { | ||
LikeButton( | ||
{ | ||
controller: this.controller | ||
} | ||
) | ||
} | ||
} | ||
.columnsTemplate('1fr 1fr 1fr') | ||
.columnsGap(10) | ||
.rowsGap(10) | ||
.width('100%') | ||
} | ||
.height('100%') | ||
.height('100%') | ||
}.title('LikeButtonDemo').titleMode(NavigationTitleMode.Mini) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
|
||
export { LikeButton } from './src/main/ets/components/LikeButton' | ||
export { LikeButton } from './src/main/ets/components/LikeButton' | ||
|
||
export { default as like_button } from './src/main/ets/common/Controller' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,133 @@ | ||
export default like_button; | ||
import { BubblesColor, CircleColor } from './Model'; | ||
import animator, { AnimatorOptions, AnimatorResult } from '@ohos.animator'; | ||
import { Cubic, DecelerateCurve, Interval, OvershootCurve } from './Curve'; | ||
|
||
|
||
namespace like_button { | ||
export class Controller { | ||
onTap() { | ||
/// size of like widget | ||
likeComponentSize: number = 30; | ||
/// animation duration to change isLiked state | ||
// final Duration animationDuration; | ||
|
||
/// total size of bubbles | ||
bubblesSize: number; | ||
/// colors of bubbles | ||
bubblesColor: BubblesColor = new BubblesColor( | ||
{ dotPrimaryColor: '#FFFFC107', | ||
dotSecondaryColor: '#FFFF9800', | ||
dotThirdColor: '#FFFF5722', | ||
dotLastColor: '#FFF44336', } | ||
); | ||
/// size of circle | ||
circleSize: number; | ||
/// colors of circle | ||
circleColor: CircleColor = new CircleColor({ start: '#FFFF5722', end: '#FFFFC107', }); | ||
/// tap call back of like button | ||
// final LikeButtonTapCallback? onTap; | ||
/// whether it is liked | ||
/// it's initial value | ||
/// you can get current value from onTap/countBuilder | ||
isLiked: boolean | null = false; | ||
/// animation duration to change isLiked state | ||
animationDuration: number = 1000; | ||
outerCircleRadiusProgress: number = 0; | ||
innerCircleRadiusProgress: number = 0; | ||
bubblesProgress: number = 0; | ||
iconScale: number = 0; | ||
_animatorResult: AnimatorResult | undefined = undefined; | ||
onTap: (isLike: boolean) => Promise<boolean>; | ||
private outerCircleCurve = new Interval({ | ||
begin: 0.0, | ||
end: 0.3, | ||
curve: Cubic.ease, | ||
beginValue: 0.1, | ||
endValue: 1.0, | ||
}); | ||
private innerCircleCurve = new Interval({ | ||
begin: 0.2, | ||
end: 0.5, | ||
curve: Cubic.ease, | ||
beginValue: 0.2, | ||
endValue: 1.0, | ||
}); | ||
private bubblesCurve = new Interval({ | ||
begin: 0.1, | ||
end: 1.0, | ||
curve: new DecelerateCurve(), | ||
beginValue: 0.0, | ||
endValue: 1.0, | ||
}); | ||
private iconScaleCurve = new Interval({ | ||
begin: 0.35, | ||
end: 0.7, | ||
curve: new OvershootCurve(), | ||
beginValue: 0.1, | ||
endValue: 1.0 | ||
}); | ||
|
||
initAnimation() { | ||
|
||
let options: AnimatorOptions = { | ||
duration: this.animationDuration, | ||
easing: "ease", | ||
delay: 0, | ||
fill: "forwards", | ||
direction: "normal", | ||
iterations: 1, | ||
begin: 0.0, | ||
end: 1.0 | ||
}; | ||
// curve: const Interval( | ||
// 0.0, | ||
// 0.3, | ||
// curve: Curves.ease, | ||
// ), | ||
|
||
this._animatorResult = animator.create(options); | ||
this._animatorResult.onframe = (value: number) => { | ||
this.outerCircleRadiusProgress = this.outerCircleCurve.transform(value); | ||
this.innerCircleRadiusProgress = this.innerCircleCurve.transform(value); | ||
this.bubblesProgress = this.bubblesCurve.transform(value); | ||
this.iconScale = this.iconScaleCurve.transform(value); | ||
}; | ||
this._animatorResult.onfinish = () => { | ||
this._animatorResult = undefined; | ||
} | ||
} | ||
|
||
public isAnimating(): boolean { | ||
return this._animatorResult != undefined; | ||
|
||
} | ||
|
||
play() { | ||
if (this.isAnimating()) { | ||
return; | ||
} | ||
this.initAnimation(); | ||
this._animatorResult.play(); | ||
} | ||
|
||
dispose() { | ||
if (this._animatorResult != undefined) { | ||
this._animatorResult.cancel(); | ||
this._animatorResult = undefined; | ||
} | ||
} | ||
|
||
Tap() { | ||
if (this.isAnimating()) { | ||
return; | ||
} | ||
this.onTap(this.isLiked).then((value) => { | ||
this.isLiked = value; | ||
if (this.isLiked) { | ||
this.play(); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default like_button; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.