Skip to content

Commit

Permalink
优化语法写法,以适配最新的 api 和 ide
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Dec 21, 2023
1 parent 02e46e4 commit b273445
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 65 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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;
```

## 例子
Expand Down Expand Up @@ -107,19 +103,15 @@ 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
Text(`${$$.showText}`).fontColor($$.isLiked ? '#FF004D40' : Color.Gray)
}

@Builder
buildLikeWidget8($$: { isLiked: boolean }) {
buildLikeWidget8($$: LikeWidgetBuilderParam) {
Image($r('app.media.save'))
.fillColor($$.isLiked ? '#FF004D40' : Color.Gray)
}
Expand Down
38 changes: 14 additions & 24 deletions entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
LikeButton,
like_button,
DartColor,
LikeCountAnimationType
LikeCountAnimationType,
LikeWidgetBuilderParam,
LikeCountWidgetBuilderParam,
} from '@candies/like_button';

@Entry
Expand All @@ -19,80 +21,68 @@ 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
Text(`${$$.showText}`)
}

@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
Expand Down
6 changes: 6 additions & 0 deletions like_button/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion like_button/Index.ets
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
18 changes: 5 additions & 13 deletions like_button/README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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;
```

## 例子
Expand Down Expand Up @@ -107,19 +103,15 @@ 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
Text(`${$$.showText}`).fontColor($$.isLiked ? '#FF004D40' : Color.Gray)
}

@Builder
buildLikeWidget8($$: { isLiked: boolean }) {
buildLikeWidget8($$: LikeWidgetBuilderParam) {
Image($r('app.media.save'))
.fillColor($$.isLiked ? '#FF004D40' : Color.Gray)
}
Expand Down
Empty file added like_button/example/Index.ets
Empty file.
4 changes: 2 additions & 2 deletions like_button/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
26 changes: 14 additions & 12 deletions like_button/src/main/ets/components/LikeButton.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> = async (isLike: boolean) => {
return !isLike;
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -153,11 +149,7 @@ export struct LikeButton {
}

@Builder
buildLikeCountWidget($$: {
isLiked: boolean,
likeCount: number,
showText: string
}) {
buildLikeCountWidget($$: LikeCountWidgetBuilderParam) {
Text(`${$$.showText}`)
}

Expand Down Expand Up @@ -403,4 +395,14 @@ export struct LikeButton {
}
}
}
}

export class LikeCountWidgetBuilderParam {
isLiked: boolean;
likeCount: number;
showText: string;
}

export class LikeWidgetBuilderParam {
isLiked: boolean;
}

0 comments on commit b273445

Please sign in to comment.