diff --git a/bundle.json b/bundle.json
index c1bf0a65183f23b6581726766a2580a34336cf0e..85da6451b25fbacd758f3c82ef182d55af6ab601 100644
--- a/bundle.json
+++ b/bundle.json
@@ -37,7 +37,8 @@
"//foundation/arkui/advanced_ui_component/interface/swiperefresher:swiperefresher",
"//foundation/arkui/advanced_ui_component/interface/arkdialog:arkdialog",
"//foundation/arkui/advanced_ui_component/interface/toolbar:toolbar",
- "//foundation/arkui/advanced_ui_component/interface/progressbutton:progressbutton"
+ "//foundation/arkui/advanced_ui_component/interface/progressbutton:progressbutton",
+ "//foundation/arkui/advanced_ui_component/interface/downloadfilebutton:downloadfilebutton"
],
"inner_kits": [],
"test": []
diff --git a/doc/ts-composite-components-downloadfilebutton.md b/doc/ts-composite-components-downloadfilebutton.md
new file mode 100644
index 0000000000000000000000000000000000000000..8062880c58d66017ecfcad935c184640f3799df7
--- /dev/null
+++ b/doc/ts-composite-components-downloadfilebutton.md
@@ -0,0 +1,199 @@
+# DownloadFileButton
+
+下载控件,用户通过点击该下载按钮,可以获取到当前应用所属的存储路径。
+
+
+> **说明:**
+>
+> 该组件从API Version 12开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+
+## 导入模块
+
+```
+import DownloadFileButton from '@ohos.arkui.advanced.DownloadFileButton';
+```
+
+
+
+## 子组件
+
+不支持。
+
+## 接口
+
+### DownloadFileButton
+
+Downloadbutton()
+
+默认创建带有图标、文本、背景的保存按钮。
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+**系统能力**:SystemCapability.FileManagement.UserFileService
+
+**参数:**
+
+| 参数名 | 参数类型 | 必填 | 参数描述 |
+| ------------- | ----------------------------------------------- | ---- | -------------------------------- |
+| contentOption | [DownloadContentOption](#DownloadContentOption) | 否 | 创建包含指定元素内容的下载按钮。 |
+| styleOption | [DownloadStyleOption](#DownloadStyleOption) | 否 | 创建包含指定元素样式的下载按钮。 |
+
+
+
+## DownloadContentOption
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+| 名称 | 类型 | 必填 | 描述 |
+| ---- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
+| icon | [DownloadIconStyle](#DownloadIconStyle枚举说明) | 否 | 设置下载按钮的图标风格
不传入该参数表示没有图标,icon和text至少存在一个。 |
+| text | [DownloadDescription](#DownloadDescription枚举说明) | 否 | 设置下载按钮的文本描述
不传入该参数表示没有文字描述,icon和text至少存在一个。 |
+
+
+
+## DownloadStyleOption
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+| 名称 | 类型 | 必填 | 描述 |
+| --------------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
+| iconSize | Dimension | 否 | 下载控件上图标的尺寸。
默认值:16vp |
+| layoutDirection | [DownloadLayoutDirection](#DownloadLayoutDirection枚举说明) | 否 | 下载控件上图标和文字分布的方向。
默认值:DownloadLayoutDirection.HORIZONTAL |
+| fontSize | Dimension | 否 | 下载控件上文字的尺寸。
默认值:16fp |
+| fontStyle | FontStyle | 否 | 下载控件上文字的样式。
默认值:FontStyle.Normal |
+| fontWeight | number \| FontWeight \| string | 否 | 下载控件上文字粗细。
默认值:FontWeight.Medium |
+| fontFamily | string \| Resource | 否 | 下载控件上文字的字体。
默认字体:'HarmonyOS Sans' |
+| fontColor | ResourceColor | 否 | 下载控件上文字的颜色。
默认值:#ffffffff |
+| iconColor | ResourceColor | 否 | 下载控件上图标的颜色。
默认值:#ffffffff |
+| textIconSpace | Dimension | 否 | 下载控件中图标和文字的间距。
默认值:4vp |
+
+
+
+## DownloadIconStyle枚举说明
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+| 名称 | 枚举值 | 描述 |
+| ----------- | ------ | -------------------------- |
+| FULL_FILLED | 0 | 下载按钮展示填充样式图标。 |
+| LINES | 1 | 下载按钮展示线条样式图标。 |
+
+
+
+## DownloadDescription枚举说明
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+| 名称 | 枚举值 | 描述 |
+| ------------------- | ------ | ------------------------------------------------------------ |
+| DOWNLOAD | 0 | 下载按钮的文字描述为“下载”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| DOWNLOAD_FILE | 1 | 下载按钮的文字描述为“下载文件”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| SAVE | 2 | 下载按钮的文字描述为“保存”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| SAVE_IMAGE | 3 | 下载按钮的文字描述为“保存图片”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| SAVE_FILE | 4 | 下载按钮的文字描述为“保存文件”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| DOWNLOAD_AND_SHARE | 5 | 下载按钮的文字描述为“下载分享”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| RECEIVE | 6 | 下载按钮的文字描述为“接收”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+| CONTINUE_TO_RECEIVE | 7 | 下载按钮的文字描述为“继续接收”。 **元服务API:** 从API version 12开始,该接口支持在元服务中使用。 |
+
+
+
+## DownloadLayoutDirection枚举说明
+
+**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
+
+| 名称 | 枚举值 | 描述 |
+| ---------- | ------ | ------------------------------------------ |
+| HORIZONTAL | 0 | 下载控件上图标和文字分布的方向为水平排列。 |
+| VERTICAL | 1 | 下载控件上图标和文字分布的方向为垂直排列。 |
+
+
+
+## 示例
+
+```
+import picker from '@ohos.file.picker';
+import { BusinessError } from '@kit.BasicServicesKit';
+import DownloadFileButton from '@ohos.arkui.advanced.DownloadFileButton';
+
+@Entry
+@Component
+struct Index {
+ build() {
+ Column() {
+ DownloadFileButton({
+ contentOption: {
+ // icon: DownloadIconStyle.FULL_FILLED,
+ // text: DownloadDescription.DOWNLOAD
+ },
+ styleOption: {
+ iconSize: '16vp',
+ layoutDirection: DownloadLayoutDirection.HORIZONTAL,
+ fontSize: '16vp',
+ fontStyle: FontStyle.Normal,
+ fontWeight: FontWeight.Medium,
+ fontFamily: 'HarmonyOS Sans',
+ fontColor: '#ffffffff',
+ iconColor: '#ffffffff',
+ textIconSpace: '4vp'
+ }
+ })
+ .backgroundColor('#007dff')
+ .borderStyle(BorderStyle.Dotted)
+ .borderWidth(0)
+ .borderColor('')
+ .borderRadius('24vp')
+ .position({ x: 0, y: 0 })
+ .markAnchor({ x: 0, y: 0 })
+ .offset({ x: 0, y: 0 })
+ .constraintSize({})
+ .padding({
+ top: '12vp',
+ bottom: '12vp',
+ left: '24vp',
+ right: '24vp'
+ })
+ .onClick(() => {
+ this.downloadAction();
+ })
+ }
+ }
+
+ downloadAction() {
+ try {
+ const document = new picker.DocumentSaveOptions();
+ document.pickerMode = picker.DocumentPickerMode.DOWNLOAD;
+ new picker.DocumentViewPicker().save(document, (err: BusinessError, result: Array) => {
+ if (err) {
+ return;
+ }
+ console.info(`downloadAction result: ${JSON.stringify(result)}`);
+ });
+ } catch (e) {
+ }
+ }
+}
+
+
+
+...
+ contentOption: {
+ text: DownloadDescription.DOWNLOAD
+ }
+...
+
+
+...
+ contentOption: {
+ icon: DownloadIconStyle.FULL_FILLED
+ }
+ ..
+ styleOption: {
+ iconColor: '#007dff'
+ }
+ ..
+ // .backgroundColor('#007dff')
+...
+```
+
+
+
diff --git a/interface/downloadfilebutton/BUILD.gn b/interface/downloadfilebutton/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..6598bb0c52db3fd4ce4b748d8e733a777080df2c
--- /dev/null
+++ b/interface/downloadfilebutton/BUILD.gn
@@ -0,0 +1,47 @@
+# Copyright (C) 2023 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//foundation/arkui/ace_engine/ace_config.gni")
+import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
+
+es2abc_gen_abc("gen_downloadfilebutton_abc") {
+ src_js = rebase_path("downloadfilebutton.js")
+ dst_file = rebase_path(target_out_dir + "/downloadfilebutton.abc")
+ in_puts = [ "downloadfilebutton.js" ]
+ out_puts = [ target_out_dir + "/downloadfilebutton.abc" ]
+ extra_args = [ "--module" ]
+}
+
+gen_js_obj("downloadfilebutton_abc") {
+ input = get_label_info(":gen_downloadfilebutton_abc", "target_out_dir") + "/downloadfilebutton.abc"
+ output = target_out_dir + "/downloadfilebutton_abc.o"
+ dep = ":gen_downloadfilebutton_abc"
+}
+
+
+ohos_shared_library("downloadfilebutton") {
+ sources = [ "downloadfilebutton.cpp" ]
+ deps = [ ":downloadfilebutton_abc" ]
+
+
+ external_deps = [
+ "hilog:libhilog",
+ "napi:ace_napi",
+ ]
+
+ subsystem_name = "arkui"
+ part_name = "advanced_ui_component"
+
+ relative_install_dir = "module/arkui/advanced"
+}
diff --git a/interface/downloadfilebutton/downloadfilebutton.cpp b/interface/downloadfilebutton/downloadfilebutton.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..01202d2564eb2836b6a0ef107a7da0685580958e
--- /dev/null
+++ b/interface/downloadfilebutton/downloadfilebutton.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2023-2024 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+#include "native_engine/native_engine.h"
+
+extern const char _binary_downloadfilebutton_abc_start[];
+extern const char _binary_downloadfilebutton_abc_end[];
+
+extern "C" __attribute__((visibility("default")))
+void NAPI_arkui_advanced_DownloadFileButton_GetABCCode(const char **buf, int *buflen)
+{
+ if (buf != nullptr) {
+ *buf = _binary_downloadfilebutton_abc_start;
+ }
+ if (buflen != nullptr) {
+ *buflen = _binary_downloadfilebutton_abc_end - _binary_downloadfilebutton_abc_start;
+ }
+}
+/*
+ * Module define
+ */
+static napi_module downloadfilebuttonModule = {
+ .nm_version = 1,
+ .nm_flags = 0,
+ .nm_filename = nullptr,
+ .nm_modname = "arkui.advanced.DownloadFileButton",
+ .nm_priv = ((void*)0),
+ .reserved = { 0 },
+};
+/*
+ * Module register function
+ */
+extern "C" __attribute__((constructor)) void downloadfilebuttonRegisterModule(void)
+{
+ napi_module_register(&downloadfilebuttonModule);
+}
\ No newline at end of file
diff --git a/interface/downloadfilebutton/downloadfilebutton.js b/interface/downloadfilebutton/downloadfilebutton.js
new file mode 100644
index 0000000000000000000000000000000000000000..0412fe98359f49ec6d6810459b5624f31756ca4f
--- /dev/null
+++ b/interface/downloadfilebutton/downloadfilebutton.js
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+export var DownloadIconStyle;
+(function (o2) {
+ o2[o2["FULL_FILLED"] = 0] = "FULL_FILLED";
+ o2[o2["LINES"] = 1] = "LINES";
+})(DownloadIconStyle || (DownloadIconStyle = {}));
+export var DownloadDescription;
+(function (n2) {
+ n2[n2["DOWNLOAD"] = 0] = "DOWNLOAD";
+ n2[n2["DOWNLOAD_FILE"] = 1] = "DOWNLOAD_FILE";
+ n2[n2["SAVE"] = 2] = "SAVE";
+ n2[n2["SAVE_IMAGE"] = 3] = "SAVE_IMAGE";
+ n2[n2["SAVE_FILE"] = 4] = "SAVE_FILE";
+ n2[n2["DOWNLOAD_AND_SHARE"] = 5] = "DOWNLOAD_AND_SHARE";
+ n2[n2["RECEIVE"] = 6] = "RECEIVE";
+ n2[n2["CONTINUE_TO_RECEIVE"] = 7] = "CONTINUE_TO_RECEIVE";
+})(DownloadDescription || (DownloadDescription = {}));
+export var DownloadLayoutDirection;
+(function (m2) {
+ m2[m2["HORIZONTAL"] = 0] = "HORIZONTAL";
+ m2[m2["VERTICAL"] = 1] = "VERTICAL";
+})(DownloadLayoutDirection || (DownloadLayoutDirection = {}));
+const downloadDescriptionResourceMap = new Map([
+ [DownloadDescription.DOWNLOAD, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_download"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.DOWNLOAD_FILE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_download_file"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.SAVE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_save"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.SAVE_IMAGE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_save_image"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.SAVE_FILE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_save_file"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.DOWNLOAD_AND_SHARE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_download_and_share"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.RECEIVE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_receive"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }],
+ [DownloadDescription.CONTINUE_TO_RECEIVE, { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_continue_to_receive"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }]
+]);
+export class DownloadFileButton extends ViewPU {
+ constructor(g2, h2, i2, j2 = -1, k2 = undefined, l2) {
+ super(g2, i2, j2, l2);
+ if (typeof k2 === "function") {
+ this.paramsGenerator_ = k2;
+ }
+ this.__contentOption = new ObservedPropertyObjectPU({}, this, "contentOption");
+ this.__styleOption = new ObservedPropertyObjectPU({
+ iconSize: '16vp',
+ layoutDirection: DownloadLayoutDirection.HORIZONTAL,
+ fontSize: '16fp',
+ fontStyle: FontStyle.Normal,
+ fontWeight: FontWeight.Medium,
+ fontFamily: 'HarmonyOS Sans',
+ fontColor: '#ffffffff',
+ iconColor: '#ffffffff',
+ textIconSpace: '4vp'
+ }, this, "styleOption");
+ this.setInitiallyProvidedValue(h2);
+ }
+ setInitiallyProvidedValue(f2) {
+ if (f2.contentOption !== undefined) {
+ this.contentOption = f2.contentOption;
+ }
+ if (f2.styleOption !== undefined) {
+ this.styleOption = f2.styleOption;
+ }
+ }
+ updateStateVars(e2) {
+ }
+ purgeVariableDependenciesOnElmtId(d2) {
+ this.__contentOption.purgeDependencyOnElmtId(d2);
+ this.__styleOption.purgeDependencyOnElmtId(d2);
+ }
+ aboutToBeDeleted() {
+ this.__contentOption.aboutToBeDeleted();
+ this.__styleOption.aboutToBeDeleted();
+ SubscriberManager.Get().delete(this.id__());
+ this.aboutToBeDeletedInternal();
+ }
+ get contentOption() {
+ return this.__contentOption.get();
+ }
+ set contentOption(c2) {
+ this.__contentOption.set(c2);
+ }
+ get styleOption() {
+ return this.__styleOption.get();
+ }
+ set styleOption(b2) {
+ this.__styleOption.set(b2);
+ }
+ initialRender() {
+ this.observeComponentCreation2((z1, a2) => {
+ Row.create();
+ }, Row);
+ this.observeComponentCreation2((k, l) => {
+ If.create();
+ if (this.contentOption.text === undefined && this.contentOption.icon === undefined) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.observeComponentCreation2((s1, t1) => {
+ If.create();
+ if (this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.downloadImage.bind(this)();
+ this.downloadText.bind(this)();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ this.observeComponentCreation2((w1, x1) => {
+ Column.create();
+ }, Column);
+ this.downloadImage.bind(this)();
+ this.downloadText.bind(this)();
+ Column.pop();
+ });
+ }
+ }, If);
+ If.pop();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ this.observeComponentCreation2((o, p) => {
+ If.create();
+ if (this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.observeComponentCreation2((m1, n1) => {
+ If.create();
+ if (this.contentOption.icon !== undefined) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.downloadImage.bind(this)();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ });
+ }
+ }, If);
+ If.pop();
+ this.observeComponentCreation2((i1, j1) => {
+ If.create();
+ if (this.contentOption.text !== undefined) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.downloadText.bind(this)();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ });
+ }
+ }, If);
+ If.pop();
+ });
+ }
+ else if (this.styleOption.layoutDirection === DownloadLayoutDirection.VERTICAL) {
+ this.ifElseBranchUpdateFunction(1, () => {
+ this.observeComponentCreation2((d1, e1) => {
+ Column.create();
+ }, Column);
+ this.observeComponentCreation2((z, a1) => {
+ If.create();
+ if (this.contentOption.icon !== undefined) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.downloadImage.bind(this)();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ });
+ }
+ }, If);
+ If.pop();
+ this.observeComponentCreation2((v, w) => {
+ If.create();
+ if (this.contentOption.text !== undefined) {
+ this.ifElseBranchUpdateFunction(0, () => {
+ this.downloadText.bind(this)();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(1, () => {
+ });
+ }
+ }, If);
+ If.pop();
+ Column.pop();
+ });
+ }
+ else {
+ this.ifElseBranchUpdateFunction(2, () => {
+ });
+ }
+ }, If);
+ If.pop();
+ });
+ }
+ }, If);
+ If.pop();
+ Row.pop();
+ }
+ downloadImage(e = null) {
+ this.observeComponentCreation2((g, h) => {
+ Image.create(this.contentOption.icon === DownloadIconStyle.LINES
+ ? { "id": -1, "type": 20000, params: ["sys.media.ohos_ic_public_save_button_line"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" } : { "id": -1, "type": 20000, params: ["sys.media.ohos_ic_public_save_button_filled"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
+ Image.size({ width: this.styleOption.iconSize, height: this.styleOption.iconSize });
+ Image.fillColor(this.styleOption.iconColor);
+ }, Image);
+ }
+ downloadText(a = null) {
+ this.observeComponentCreation2((c, d) => {
+ Text.create(!this.contentOption.text || !downloadDescriptionResourceMap.get(this.contentOption.text) ? { "id": -1, "type": 10003, params: ["sys.string.ohos_id_text_save_button_description_download"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" } :
+ downloadDescriptionResourceMap.get(this.contentOption.text));
+ Text.fontSize(this.styleOption.fontSize);
+ Text.fontColor(this.styleOption.fontColor);
+ Text.fontStyle(this.styleOption.fontStyle);
+ Text.fontWeight(this.styleOption.fontWeight);
+ Text.fontFamily(this.styleOption.fontFamily);
+ Text.margin({
+ top: this.styleOption.layoutDirection === DownloadLayoutDirection.VERTICAL ? this.styleOption.textIconSpace :
+ '0vp',
+ left: this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL ?
+ this.styleOption.textIconSpace :
+ '0vp'
+ });
+ }, Text);
+ Text.pop();
+ }
+ rerender() {
+ this.updateDirtyElements();
+ }
+}
\ No newline at end of file
diff --git a/source/DownloadFileButton/DownloadFileButton.ets b/source/DownloadFileButton/DownloadFileButton.ets
new file mode 100644
index 0000000000000000000000000000000000000000..885b64762cf5f0242dd6b3dd43e62ea285d71928
--- /dev/null
+++ b/source/DownloadFileButton/DownloadFileButton.ets
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export enum DownloadIconStyle {
+ FULL_FILLED = 0,
+ LINES = 1
+}
+
+export enum DownloadDescription {
+ DOWNLOAD = 0,
+ DOWNLOAD_FILE = 1,
+ SAVE = 2,
+ SAVE_IMAGE = 3,
+ SAVE_FILE = 4,
+ DOWNLOAD_AND_SHARE = 5,
+ RECEIVE = 6,
+ CONTINUE_TO_RECEIVE = 7
+}
+
+export enum DownloadLayoutDirection {
+ HORIZONTAL,
+ VERTICAL
+}
+
+const downloadDescriptionResourceMap = new Map([
+ [DownloadDescription.DOWNLOAD, $r("sys.string.ohos_id_text_save_button_description_download")],
+ [DownloadDescription.DOWNLOAD_FILE, $r("sys.string.ohos_id_text_save_button_description_download_file")],
+ [DownloadDescription.SAVE, $r("sys.string.ohos_id_text_save_button_description_save")],
+ [DownloadDescription.SAVE_IMAGE, $r("sys.string.ohos_id_text_save_button_description_save_image")],
+ [DownloadDescription.SAVE_FILE, $r("sys.string.ohos_id_text_save_button_description_save_file")],
+ [DownloadDescription.DOWNLOAD_AND_SHARE, $r("sys.string.ohos_id_text_save_button_description_download_and_share")],
+ [DownloadDescription.RECEIVE, $r("sys.string.ohos_id_text_save_button_description_receive")],
+ [DownloadDescription.CONTINUE_TO_RECEIVE, $r("sys.string.ohos_id_text_save_button_description_continue_to_receive")]
+]);
+
+export interface DownloadContentOption {
+ icon?: DownloadIconStyle;
+ text?: DownloadDescription;
+}
+
+export interface DownloadStyleOption {
+ iconSize?: Dimension;
+ layoutDirection?: DownloadLayoutDirection;
+ fontSize?: Dimension;
+ fontStyle?: FontStyle;
+ fontWeight?: number | FontWeight | string;
+ fontFamily?: string | Resource;
+ fontColor?: ResourceColor;
+ iconColor?: ResourceColor;
+ textIconSpace?: Dimension;
+}
+
+@Component
+export struct DownloadFileButton {
+ @State contentOption: DownloadContentOption = {};
+ @State styleOption: DownloadStyleOption = {
+ iconSize: '16vp',
+ layoutDirection: DownloadLayoutDirection.HORIZONTAL,
+ fontSize: '16fp',
+ fontStyle: FontStyle.Normal,
+ fontWeight: FontWeight.Medium,
+ fontFamily: 'HarmonyOS Sans',
+ fontColor: '#ffffffff',
+ iconColor: '#ffffffff',
+ textIconSpace: '4vp'
+ };
+
+ build() {
+ Row() {
+ if (this.contentOption.text === undefined && this.contentOption.icon === undefined) {
+ if (this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL) {
+ this.downloadImage();
+ this.downloadText();
+ } else {
+ Column() {
+ this.downloadImage();
+ this.downloadText();
+ }
+ }
+ } else {
+ if (this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL) {
+ if (this.contentOption.icon !== undefined) {
+ this.downloadImage();
+ }
+ if (this.contentOption.text !== undefined) {
+ this.downloadText();
+ }
+ } else if (this.styleOption.layoutDirection === DownloadLayoutDirection.VERTICAL) {
+ Column() {
+ if (this.contentOption.icon !== undefined) {
+ this.downloadImage();
+ }
+ if (this.contentOption.text !== undefined) {
+ this.downloadText();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Builder
+ downloadImage() {
+ Image(this.contentOption.icon === DownloadIconStyle.LINES
+ ? $r("sys.media.ohos_ic_public_save_button_line") : $r("sys.media.ohos_ic_public_save_button_filled"))
+ .size({ width: this.styleOption.iconSize, height: this.styleOption.iconSize })
+ .fillColor(this.styleOption.iconColor)
+ }
+
+ @Builder
+ downloadText() {
+ Text(!this.contentOption.text || !downloadDescriptionResourceMap.get(this.contentOption.text) ?
+ $r("sys.string.ohos_id_text_save_button_description_download") :
+ downloadDescriptionResourceMap.get(this.contentOption.text))
+ .fontSize(this.styleOption.fontSize)
+ .fontColor(this.styleOption.fontColor)
+ .fontStyle(this.styleOption.fontStyle)
+ .fontWeight(this.styleOption.fontWeight)
+ .fontFamily(this.styleOption.fontFamily)
+ .margin({
+ top: this.styleOption.layoutDirection === DownloadLayoutDirection.VERTICAL ? this.styleOption.textIconSpace :
+ '0vp',
+ left: this.styleOption.layoutDirection === DownloadLayoutDirection.HORIZONTAL ?
+ this.styleOption.textIconSpace :
+ '0vp'
+ })
+ }
+}