From b273445b48591629c51dd90e7c32a29f47cd29e9 Mon Sep 17 00:00:00 2001 From: zmtzawqlp Date: Mon, 11 Dec 2023 22:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=AD=E6=B3=95=E5=86=99?= =?UTF-8?q?=E6=B3=95,=E4=BB=A5=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84=20api=20=E5=92=8C=20ide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++------ entry/src/main/ets/pages/Index.ets | 38 +++++++------------ like_button/CHANGELOG.md | 6 +++ like_button/Index.ets | 2 +- like_button/README.md | 18 +++------ like_button/example/Index.ets | 0 like_button/oh-package.json5 | 4 +- .../src/main/ets/components/LikeButton.ets | 26 +++++++------ 8 files changed, 47 insertions(+), 65 deletions(-) create mode 100644 like_button/example/Index.ets diff --git a/README.md b/README.md index 4376178..37a59d1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # like_button -Like Button 支持推特点赞效果和喜欢数量动画的Flutter库. +Like Button 支持推特点赞效果和点赞数量动画的 ArkUI 库. ![LikeButton](https://github.com/HarmonyCandies/HarmonyCandies/blob/main/gif/like_button/LikeButton.gif) @@ -59,13 +59,9 @@ Like Button 支持推特点赞效果和喜欢数量动画的Flutter库. ```typescript @BuilderParam - likeWidgetBuilder?: ($$: { isLiked: boolean }) => void = this.buildLikeWidget.bind(this); + likeWidgetBuilder?: ($$: LikeWidgetBuilderParam) => void = this.buildLikeWidget; @BuilderParam - likeCountWidgetBuilder?: ($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) => void = this.buildLikeCountWidget.bind(this); + likeCountWidgetBuilder?: ($$: LikeCountWidgetBuilderParam) => void = this.buildLikeCountWidget; ``` ## 例子 @@ -107,11 +103,7 @@ LikeButton( ) @Builder -buildLikeCountWidget2($$: { - isLiked: boolean, - likeCount: number, - showText: string -}) { +buildLikeCountWidget2($$: LikeCountWidgetBuilderParam) { if ($$.likeCount >= 1000) Text(`${($$.likeCount / 1000).toFixed(1)}k`).fontColor($$.isLiked ? '#FF004D40' : Color.Gray) else @@ -119,7 +111,7 @@ buildLikeCountWidget2($$: { } @Builder -buildLikeWidget8($$: { isLiked: boolean }) { +buildLikeWidget8($$: LikeWidgetBuilderParam) { Image($r('app.media.save')) .fillColor($$.isLiked ? '#FF004D40' : Color.Gray) } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 411993b..70073a7 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -4,7 +4,9 @@ import { LikeButton, like_button, DartColor, - LikeCountAnimationType + LikeCountAnimationType, + LikeWidgetBuilderParam, + LikeCountWidgetBuilderParam, } from '@candies/like_button'; @Entry @@ -19,59 +21,55 @@ struct Index { } @Builder - buildLikeWidget1($$: { isLiked: boolean }) { + buildLikeWidget1($$: LikeWidgetBuilderParam) { Image($r('app.media.bag')) .fillColor($$.isLiked ? '#FF7C4DFF' : Color.Gray) } @Builder - buildLikeWidget2($$: { isLiked: boolean }) { + buildLikeWidget2($$: LikeWidgetBuilderParam) { Image($r('app.media.clean')) .fillColor($$.isLiked ? Color.Green : Color.Gray) } @Builder - buildLikeWidget3($$: { isLiked: boolean }) { + buildLikeWidget3($$: LikeWidgetBuilderParam) { Image($r('app.media.flower')) .fillColor($$.isLiked ? Color.Red : Color.Gray) } @Builder - buildLikeWidget4($$: { isLiked: boolean }) { + buildLikeWidget4($$: LikeWidgetBuilderParam) { Image($r('app.media.color_palette')) .fillColor($$.isLiked ? '#FF40C4FF' : Color.Gray) } @Builder - buildLikeWidget5($$: { isLiked: boolean }) { + buildLikeWidget5($$: LikeWidgetBuilderParam) { Image($r('app.media.eraser')) .fillColor($$.isLiked ? '#FF212121' : Color.Gray) } @Builder - buildLikeWidget6($$: { isLiked: boolean }) { + buildLikeWidget6($$: LikeWidgetBuilderParam) { Image($r('app.media.clock')) .fillColor($$.isLiked ? '#FF536DFE' : Color.Gray) } @Builder - buildLikeWidget7($$: { isLiked: boolean }) { + buildLikeWidget7($$: LikeWidgetBuilderParam) { Image($r('app.media.lock')) .fillColor($$.isLiked ? '#FFE65100' : Color.Gray) } @Builder - buildLikeWidget8($$: { isLiked: boolean }) { + buildLikeWidget8($$: LikeWidgetBuilderParam) { Image($r('app.media.save')) .fillColor($$.isLiked ? '#FF004D40' : Color.Gray) } @Builder - buildLikeCountWidget($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) { + buildLikeCountWidget($$: LikeCountWidgetBuilderParam) { if ($$.likeCount == 0) Text('love') else @@ -79,20 +77,12 @@ struct Index { } @Builder - buildLikeCountWidget1($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) { + buildLikeCountWidget1($$: LikeCountWidgetBuilderParam) { Text(`${$$.showText}`).fontColor($$.isLiked ? '#FF536DFE' : Color.Gray) } @Builder - buildLikeCountWidget2($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) { + buildLikeCountWidget2($$: LikeCountWidgetBuilderParam) { if ($$.likeCount >= 1000) Text(`${($$.likeCount / 1000).toFixed(1)}k`).fontColor($$.isLiked ? '#FF004D40' : Color.Gray) else diff --git a/like_button/CHANGELOG.md b/like_button/CHANGELOG.md index c02f630..34445d5 100644 --- a/like_button/CHANGELOG.md +++ b/like_button/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.1 + +* 优化语法写法,以适配最新的 api 和 ide +1. Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types) +2. "Function.apply", "Function.bind", "Function.call" are not supported (arkts-no-func-apply-bind-call) + ## 1.0.0 * Initial Open Source release. diff --git a/like_button/Index.ets b/like_button/Index.ets index 0af841e..199ca53 100644 --- a/like_button/Index.ets +++ b/like_button/Index.ets @@ -1,4 +1,4 @@ -export { LikeButton } from './src/main/ets/components/LikeButton' +export { LikeButton, LikeWidgetBuilderParam, LikeCountWidgetBuilderParam, } from './src/main/ets/components/LikeButton' export { DartColor } from './src/main/ets/common/Color' diff --git a/like_button/README.md b/like_button/README.md index 4376178..37a59d1 100644 --- a/like_button/README.md +++ b/like_button/README.md @@ -1,5 +1,5 @@ # like_button -Like Button 支持推特点赞效果和喜欢数量动画的Flutter库. +Like Button 支持推特点赞效果和点赞数量动画的 ArkUI 库. ![LikeButton](https://github.com/HarmonyCandies/HarmonyCandies/blob/main/gif/like_button/LikeButton.gif) @@ -59,13 +59,9 @@ Like Button 支持推特点赞效果和喜欢数量动画的Flutter库. ```typescript @BuilderParam - likeWidgetBuilder?: ($$: { isLiked: boolean }) => void = this.buildLikeWidget.bind(this); + likeWidgetBuilder?: ($$: LikeWidgetBuilderParam) => void = this.buildLikeWidget; @BuilderParam - likeCountWidgetBuilder?: ($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) => void = this.buildLikeCountWidget.bind(this); + likeCountWidgetBuilder?: ($$: LikeCountWidgetBuilderParam) => void = this.buildLikeCountWidget; ``` ## 例子 @@ -107,11 +103,7 @@ LikeButton( ) @Builder -buildLikeCountWidget2($$: { - isLiked: boolean, - likeCount: number, - showText: string -}) { +buildLikeCountWidget2($$: LikeCountWidgetBuilderParam) { if ($$.likeCount >= 1000) Text(`${($$.likeCount / 1000).toFixed(1)}k`).fontColor($$.isLiked ? '#FF004D40' : Color.Gray) else @@ -119,7 +111,7 @@ buildLikeCountWidget2($$: { } @Builder -buildLikeWidget8($$: { isLiked: boolean }) { +buildLikeWidget8($$: LikeWidgetBuilderParam) { Image($r('app.media.save')) .fillColor($$.isLiked ? '#FF004D40' : Color.Gray) } diff --git a/like_button/example/Index.ets b/like_button/example/Index.ets new file mode 100644 index 0000000..e69de29 diff --git a/like_button/oh-package.json5 b/like_button/oh-package.json5 index 5e04cfd..4f886f0 100644 --- a/like_button/oh-package.json5 +++ b/like_button/oh-package.json5 @@ -9,10 +9,10 @@ ], "author": "zmtzawqlp", "name": "@candies/like_button", - "description": "Like Button is a ArkTS library that allows you to create a button with animation effects similar to Twitter\u0027s heart when you like something and animation effects to increase like count.", + "description": "Like Button 支持推特点赞效果和点赞数量动画的 ArkUI 库.", "main": "Index.ets", "repository": "https://github.com/HarmonyCandies/like_button", - "version": "1.0.0", + "version": "1.0.1", "homepage": "https://github.com/HarmonyCandies/like_button", "dependencies": {} } diff --git a/like_button/src/main/ets/components/LikeButton.ets b/like_button/src/main/ets/components/LikeButton.ets index 43db2b6..1e68fda 100644 --- a/like_button/src/main/ets/components/LikeButton.ets +++ b/like_button/src/main/ets/components/LikeButton.ets @@ -9,13 +9,9 @@ import like_button from '../common/Controller'; export struct LikeButton { controller: like_button.Controller = undefined; @BuilderParam - likeWidgetBuilder?: ($$: { isLiked: boolean }) => void = this.buildLikeWidget.bind(this); + likeWidgetBuilder?: ($$: LikeWidgetBuilderParam) => void = this.buildLikeWidget; @BuilderParam - likeCountWidgetBuilder?: ($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) => void = this.buildLikeCountWidget.bind(this); + likeCountWidgetBuilder?: ($$: LikeCountWidgetBuilderParam) => void = this.buildLikeCountWidget; /// tap call back of like button onTap: (isLike: boolean) => Promise = async (isLike: boolean) => { return !isLike; @@ -89,7 +85,7 @@ export struct LikeButton { @State _likeCountHeight: number = 0; @Builder - buildLikeWidget($$: { isLiked: boolean }) { + buildLikeWidget($$: LikeWidgetBuilderParam) { Image($r('app.media.favorite')) .fillColor($$.isLiked ? Color.Pink : Color.Gray) } @@ -153,11 +149,7 @@ export struct LikeButton { } @Builder - buildLikeCountWidget($$: { - isLiked: boolean, - likeCount: number, - showText: string - }) { + buildLikeCountWidget($$: LikeCountWidgetBuilderParam) { Text(`${$$.showText}`) } @@ -403,4 +395,14 @@ export struct LikeButton { } } } +} + +export class LikeCountWidgetBuilderParam { + isLiked: boolean; + likeCount: number; + showText: string; +} + +export class LikeWidgetBuilderParam { + isLiked: boolean; } \ No newline at end of file