Browse Source

滚动隐藏功能实现

onecold 1 năm trước cách đây
mục cha
commit
48976274a5

+ 0 - 1
entry/src/main/ets/common/util/ImageUtils.ets

@@ -24,7 +24,6 @@ import { photoAccessHelper } from '@kit.MediaLibraryKit';
 import fs from '@ohos.file.fs';
 import { FileUtil, MD5, PreferencesUtil } from '@pura/harmony-utils';
 import MediaTable from './MediaTable';
-import { FileUtils } from '@ohos/imageknife';
 
 const TAG = 'ImageUtils';
 

+ 31 - 7
entry/src/main/ets/entryability/EntryAbility.ets

@@ -19,6 +19,7 @@ import { DemoConstants } from './DemoConstants';
 import { Utility } from '../common/util/Utility';
 import { SpiderMan } from '@simplepeng/spider-man';
 import { WXApi, WXEventHandler } from '../common/util/WXApiWrap';
+import { systemShare } from '@kit.ShareKit';
 
 /**
  * 主Ability类,继承自UIAbility
@@ -57,25 +58,27 @@ export default class EntryAbility extends UIAbility {
         AppStorage.setOrCreate('context', this.context);
         hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
 
-        if (!canIUse('SystemCapability.FileManagement.AppFileService.FolderAuthorization')) {
-            console.error('this api is not supported on this device');
-            return;
-        }
+        // if (!canIUse('SystemCapability.FileManagement.AppFileService.FolderAuthorization')) {
+        //     console.error('this api is not supported on this device');
+        //     return;
+        // }
         let timeout = 5000
         if(Utility.isNoble())
-            timeout = 2000
-        setTimeout(()=>{
+            timeout = 3000
+        setTimeout(async ()=>{
             this.loadDoWant(want)
+            // await this.handleParam(want)
         },timeout)
 
         this.handleWeChatCallIfNeed(want)
 
     }
 
-    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
+    async onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
         hilog.info(0x0000, 'testTag', `onNewWant, want=${JSON.stringify(want)}`);
         super.onNewWant(want, launchParam);
         this.loadDoWant(want)
+        // await this.handleParam(want)
         this.handleWeChatCallIfNeed(want)
 
     }
@@ -106,6 +109,27 @@ export default class EntryAbility extends UIAbility {
 
     }
 
+    // 华为分享拉起接收
+    // 1. 改造 handleParam 为异步函数,让其返回 Promise
+    async handleParam(want: Want) {
+        try {
+            // 通过 await 等待异步操作完成
+            const data = await systemShare.getSharedData(want);
+            const records = data.getRecords();
+            let uri = want.uri;
+            for (const record of records) {
+                if (record.uri) {
+                    uri = record.uri;
+
+                    break;
+                }
+            }
+        } catch (error) {
+            const businessError = error as BusinessError;
+            console.error(`Failed: Code ${businessError.code}, ${businessError.message}`);
+        }
+    }
+
     onDestroy() {
         hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
     }

+ 1 - 2
entry/src/main/ets/pages/NewIndex.ets

@@ -18,7 +18,6 @@ import { CSJUtil } from '../common/util/CSJUtil';
 import { LocalMusic } from '../view/LocalMusic';
 import { StreamContent } from '../view/StreamContent';
 import { AvSessionController } from '../controller/AvSessionController';
-import { ImageKnife } from '@ohos/imageknife';
 import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
 import dataStorage from '@ohos.data.storage';
 import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
@@ -170,7 +169,7 @@ async aboutToAppear() {
   ScreenUtil.setScreenSize();
   this.bundleName =   AppUtil.getBundleName()
   this.versionName =  AppUtil.getVersionName();
-  await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
+  // await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
   this.isShowSponsorship = Utility.isOpenTime()
 }
 

+ 52 - 6
entry/src/main/ets/view/LocalMusic.ets

@@ -73,7 +73,6 @@ import { CommonConstants2 } from '../common/util/CommonConstants2';
 import { hilog } from '@kit.PerformanceAnalysisKit';
 import { LazyDataSource } from '../common/util/LazyDataSource';
 import MediaTable from '../common/util/MediaTable';
-import { ImageKnifeComponent } from '@ohos/imageknife';
 import NetAxiosUtil from '../common/util/NetAxiosUtil';
 import ImageUtils from '../common/util/ImageUtils';
 import { ringtone } from '@kit.RingtoneKit';
@@ -171,6 +170,7 @@ export struct LocalMusic {
   @State isShowHistory:boolean = true //是否显示最近播放
   @State isCustomizeBg: boolean = false //自定义背景界面
   @State isGridMusic: boolean = false //是否网格布局
+  @State isScrollHide: boolean = false //是否滚动隐藏
   @State customizeBgPath: string | undefined = '';
   @State isDarkMode: boolean = false
   @State lyricTextWeight: number = 400
@@ -366,6 +366,7 @@ export struct LocalMusic {
     this.isCustomizeBg  = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
     this.customizeBgPath  = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
     this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, false)
+    this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
     if(this.isCustomizeBg){
       this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
       this.titleBarModel.setTitleBarBackground(Color.Transparent)
@@ -483,6 +484,7 @@ export struct LocalMusic {
     this.isCustomizeBg  = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
     this.customizeBgPath  = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
     this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, false)
+    this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
     if(this.isCustomizeBg){
       this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
       this.titleBarModel.setTitleBarBackground(Color.Transparent)
@@ -1758,9 +1760,11 @@ export struct LocalMusic {
           Column() {
             this.tabTitle()
             this.listViewTitle()
-            this.getGridView()
-            this.getListView()
-
+            if(this.isGridMusic){
+              this.getGridView()
+            }else {
+              this.getListView()
+            }
           }
           .layoutWeight(1)
           .height('100%')
@@ -1875,7 +1879,7 @@ export struct LocalMusic {
         }
         .hitTestBehavior(HitTestMode.Transparent)
         .position({ bottom: 0 }) // 将 Row 固定在底部
-        .opacity(this.barOpacity)
+        .opacity(this.barBottomOpacity)
       }
       .width('100%')
       .height('100%')
@@ -2889,7 +2893,11 @@ export struct LocalMusic {
       }else if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
         (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
           this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
-        this.setBarHeightNormal()
+        if(this.isScrollHide){
+          this.setBarHeightHide2(offset)
+        }else{
+          this.setBarHeightNormal()
+        }
       }else{
         this.setBarHeightHide(offset)
       }
@@ -3296,13 +3304,20 @@ export struct LocalMusic {
       }).getValue(this.currentBreakpoint)
     )
     .onScrollFrameBegin((offset: number) => {
+
       //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
       if(this.isPhoneLan()){
         this.setBarHeightHide(offset)
       }else if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
         (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
           this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
+        if(this.isScrollHide){
+          this.setBarHeightHide2(offset)
+
+        }else{
           this.setBarHeightNormal()
+        }
+
       }else{
         this.setBarHeightHide(offset)
       }
@@ -3320,6 +3335,7 @@ export struct LocalMusic {
       this.bottomBarHeight = 55 + 0;
       this.topBarHeight = 50 + 0;
       this.barOpacity = 1;
+      this.barBottomOpacity = 1
       this.currentYOffset = 0;
       this.isHiding = false;
     });
@@ -3332,9 +3348,11 @@ export struct LocalMusic {
         this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
         this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
         this.barOpacity = 1 - this.currentYOffset / 100;
+        this.barBottomOpacity =  1 - this.currentYOffset / 100;
       } else {
         this.topBarHeight = 0;
         this.bottomBarHeight = 0;
+        this.barBottomOpacity = 0
         this.barOpacity = 0;
         this.hideDone = true;
       }
@@ -3346,6 +3364,33 @@ export struct LocalMusic {
         duration: 300
       }, () => {
         this.bottomBarHeight = 55 + 0;
+        this.topBarHeight = 50 + 0;
+        this.barOpacity = 1;
+        this.barBottomOpacity = 1
+        this.currentYOffset = 0;
+        this.isHiding = false;
+      });
+    }
+  }
+  //这个方法没隐藏bottomBar,只隐藏topBar
+  setBarHeightHide2(offset: number){
+    if (offset > 0 && !this.hideDone) {
+      this.currentYOffset += offset;
+      if (this.currentYOffset <= 100) {
+        this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
+        this.barOpacity = 1 - this.currentYOffset / 100;
+      } else {
+        this.topBarHeight = 0;
+        this.barOpacity = 0;
+        this.hideDone = true;
+      }
+      this.isHiding = true;
+    }
+    if (offset < 0 && this.isHiding) {
+      this.hideDone = false;
+      this.getUIContext().animateTo({
+        duration: 300
+      }, () => {
         this.topBarHeight = 50 + 0;
         this.barOpacity = 1;
         this.currentYOffset = 0;
@@ -4589,6 +4634,7 @@ export struct LocalMusic {
   @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
   @State topBarHeight: number = 50
   @State barOpacity: number = 1
+  @State barBottomOpacity: number = 1
   private hideDone: boolean = false;
   @State currentYOffset: number = 0;
   @State bottomBarHeight: number = 55;

+ 1 - 4
entry/src/main/module.json5

@@ -90,12 +90,9 @@
         "skills": [
           {
             "actions": [
-//              "action.system.home",
               "ohos.want.action.sendData"
             ],
-//            "entities": [
-//              "entity.system.home"
-//            ],
+
             // 目标应用在配置支持接收的数据类型时,需穷举支持的UTD,比如:支持全部图片类型,可声明:general.image
             // maxFileSupported 对于归属指定类型的文件,标识一次支持接收的最大数量。默认为0,代表不支持此类文件的分享。文件类型归属关系参考:@ohos.data.uniformTypeDescriptor (标准化数据定义与描述)
             "uris": [

+ 0 - 19
oh-package-lock.json5

@@ -10,10 +10,8 @@
     "@changwei/chardet@^1.0.0": "@changwei/chardet@1.0.0",
     "@chinalike/popup@^0.0.7": "@chinalike/popup@0.0.7",
     "@keke/color-picker@^1.0.4": "@keke/color-picker@1.0.4",
-    "@ohos/gpu_transform@^1.0.2": "@ohos/gpu_transform@1.0.4",
     "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
     "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19",
-    "@ohos/imageknife@^3.2.3": "@ohos/imageknife@3.2.3",
     "@ohos/lottie@^2.0.19": "@ohos/lottie@2.0.19",
     "@ohos/pulltorefresh@^2.1.1": "@ohos/pulltorefresh@2.1.1",
     "@pura/harmony-dialog@^1.0.6": "@pura/harmony-dialog@1.0.6",
@@ -72,13 +70,6 @@
       "resolved": "https://repo.harmonyos.com/ohpm/@keke/color-picker/-/color-picker-1.0.4.har",
       "registryType": "ohpm"
     },
-    "@ohos/gpu_transform@1.0.4": {
-      "name": "@ohos/gpu_transform",
-      "version": "1.0.4",
-      "integrity": "sha512-PrKlOK66kzObw/ANIzt55YMrOLLmtrhmAZIE2c/60GBoTl7+NLxONeHA2NsDZuiW+A0KnD4QylDYWH4/yo8T0w==",
-      "resolved": "https://repo.harmonyos.com/ohpm/@ohos/gpu_transform/-/gpu_transform-1.0.4.har",
-      "registryType": "ohpm"
-    },
     "@ohos/hamock@1.0.0": {
       "name": "@ohos/hamock",
       "version": "1.0.0",
@@ -93,16 +84,6 @@
       "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.19.har",
       "registryType": "ohpm"
     },
-    "@ohos/imageknife@3.2.3": {
-      "name": "@ohos/imageknife",
-      "version": "3.2.3",
-      "integrity": "sha512-QAuTdId4UyDUra53YWqbBlKegujty+LYfFRlYTGNckSYQ9tXtECWmrgyvTrjO2rVaGPey4+tJ/+3i7zQ9tZF7Q==",
-      "resolved": "https://repo.harmonyos.com/ohpm/@ohos/imageknife/-/imageknife-3.2.3.har",
-      "registryType": "ohpm",
-      "dependencies": {
-        "@ohos/gpu_transform": "^1.0.2"
-      }
-    },
     "@ohos/lottie@2.0.19": {
       "name": "@ohos/lottie",
       "version": "2.0.19",

+ 0 - 1
oh-package.json5

@@ -25,7 +25,6 @@
     "@seagazer/cclyric": "file:./lib",
     "@changwei/chardet": "^1.0.0",
     "@cashier_alipay/cashiersdk": "^15.8.32",
-    "@ohos/imageknife": "^3.2.3",
     "@simplepeng/spider-man": "^1.0.1",
     "@keke/color-picker": "^1.0.4",
     "@sgaolei/lrc_parser": "^1.0.0"

+ 0 - 24
oh_modules/.ohpm/lock.json5

@@ -51,10 +51,6 @@
           "specifier": "^15.8.32",
           "version": "15.8.32"
         },
-        "@ohos/imageknife": {
-          "specifier": "^3.2.3",
-          "version": "3.2.3"
-        },
         "@simplepeng/spider-man": {
           "specifier": "^1.0.1",
           "version": "1.0.1"
@@ -275,26 +271,6 @@
       "dynamic": false,
       "maskedByOverrideDependencyMap": false
     },
-    "@ohos/imageknife@3.2.3": {
-      "integrity": "sha512-QAuTdId4UyDUra53YWqbBlKegujty+LYfFRlYTGNckSYQ9tXtECWmrgyvTrjO2rVaGPey4+tJ/+3i7zQ9tZF7Q==",
-      "storePath": "oh_modules/.ohpm/@ohos+imageknife@3.2.3",
-      "dependencies": {
-        "@ohos/gpu_transform": "1.0.4"
-      },
-      "dynamicDependencies": {},
-      "dev": false,
-      "dynamic": false,
-      "maskedByOverrideDependencyMap": false
-    },
-    "@ohos/gpu_transform@1.0.4": {
-      "integrity": "sha512-PrKlOK66kzObw/ANIzt55YMrOLLmtrhmAZIE2c/60GBoTl7+NLxONeHA2NsDZuiW+A0KnD4QylDYWH4/yo8T0w==",
-      "storePath": "oh_modules/.ohpm/@ohos+gpu_transform@1.0.4",
-      "dependencies": {},
-      "dynamicDependencies": {},
-      "dev": false,
-      "dynamic": false,
-      "maskedByOverrideDependencyMap": false
-    },
     "@simplepeng/spider-man@1.0.1": {
       "integrity": "sha512-rulclyolBPbYUzEav8crOr5WDuQs+zVWpLtefE2ei0YmBIbVUrpJN8mDRPNI+5kHZdkbYufKWyM/IzbVB/KoKg==",
       "storePath": "oh_modules/.ohpm/@simplepeng+spider-man@1.0.1",