zhangbo1_wd

集成图片框架ImageKnife,底导用图片框架加载icon

@@ -7,6 +7,7 @@ import { MinePageComponent } from 'wdComponent/src/main/ets/components/page/Mine @@ -7,6 +7,7 @@ import { MinePageComponent } from 'wdComponent/src/main/ets/components/page/Mine
7 import { CompUtils, TopNavigationComponent, TopNavigationComponentNew } from 'wdComponent/Index'; 7 import { CompUtils, TopNavigationComponent, TopNavigationComponentNew } from 'wdComponent/Index';
8 import { VideoChannelPage } from './VideoChannelPage'; 8 import { VideoChannelPage } from './VideoChannelPage';
9 import ChannelViewModel from 'wdComponent/src/main/ets/viewmodel/ChannelViewModel'; 9 import ChannelViewModel from 'wdComponent/src/main/ets/viewmodel/ChannelViewModel';
  10 +import { ImageKnifeComponent, ImageKnifeOption, NONE } from '@ohos/imageknife';
10 11
11 const TAG = 'BottomNavigationComponent'; 12 const TAG = 'BottomNavigationComponent';
12 PersistentStorage.persistProp('channelIds', ''); 13 PersistentStorage.persistProp('channelIds', '');
@@ -134,16 +135,26 @@ export struct BottomNavigationComponent { @@ -134,16 +135,26 @@ export struct BottomNavigationComponent {
134 @Builder 135 @Builder
135 tabBarBuilder(navItem: BottomNavDTO, index: number) { 136 tabBarBuilder(navItem: BottomNavDTO, index: number) {
136 Stack({ alignContent: Alignment.Bottom }) { 137 Stack({ alignContent: Alignment.Bottom }) {
137 - Image(this.getBottomIcon(navItem, this.currentNavIndex === index))  
138 - .height(CommonConstants.FULL_PARENT) 138 + // Image(this.getBottomIcon(navItem, this.currentNavIndex === index))
  139 + // .height(CommonConstants.FULL_PARENT)
  140 + // .padding({
  141 + // bottom: 15,
  142 + // left: 10,
  143 + // right: 10,
  144 + // top: 2
  145 + // })
  146 + // .aspectRatio(this.ASPECT_RATIO_1_1)
  147 + // .alt(this.getBottomLocalIcon(navItem, this.currentNavIndex === index))
  148 + ImageKnifeComponent({ imageKnifeOption: this.getBottomImageKnifeOption(navItem, this.currentNavIndex === index) })
139 .padding({ 149 .padding({
140 bottom: 15, 150 bottom: 15,
141 left: 10, 151 left: 10,
142 right: 10, 152 right: 10,
143 top: 2 153 top: 2
144 }) 154 })
145 - .aspectRatio(this.ASPECT_RATIO_1_1)  
146 - .alt(this.getBottomLocalIcon(navItem, this.currentNavIndex === index)) 155 + .width('100%')
  156 + .height('100%')
  157 + .enabled(false)
147 158
148 Text(navItem.name) 159 Text(navItem.name)
149 .margin({ bottom: $r('app.float.bottom_navigation_margin_bottom') }) 160 .margin({ bottom: $r('app.float.bottom_navigation_margin_bottom') })
@@ -157,6 +168,7 @@ export struct BottomNavigationComponent { @@ -157,6 +168,7 @@ export struct BottomNavigationComponent {
157 .height($r('app.float.bottom_navigation_barHeight')) 168 .height($r('app.float.bottom_navigation_barHeight'))
158 .hoverEffect(HoverEffect.Highlight) 169 .hoverEffect(HoverEffect.Highlight)
159 .visibility(this.displayDirection === DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None) 170 .visibility(this.displayDirection === DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
  171 + // .hitTestBehavior(HitTestMode.Block)
160 .onClick(() => { 172 .onClick(() => {
161 Logger.info(TAG, `onChange, index: ${index}`); 173 Logger.info(TAG, `onChange, index: ${index}`);
162 this.onBottomNavigationIndexChange(navItem, index) 174 this.onBottomNavigationIndexChange(navItem, index)
@@ -164,6 +176,24 @@ export struct BottomNavigationComponent { @@ -164,6 +176,24 @@ export struct BottomNavigationComponent {
164 176
165 } 177 }
166 178
  179 + getBottomImageKnifeOption(navItem: BottomNavDTO, isSelect: boolean): ImageKnifeOption {
  180 + let defaultIcon = this.getBottomLocalIcon(navItem, isSelect)
  181 + let url = this.getBottomIcon(navItem, isSelect)
  182 +
  183 + let imageKnifeOption: ImageKnifeOption = {
  184 + loadSrc: url,
  185 + // 占位图使用本地资源
  186 + placeholderSrc: defaultIcon,
  187 + // 失败占位图使用本地资源
  188 + errorholderSrc: defaultIcon,
  189 + // 是否开启一级内存缓存
  190 + isCacheable: true,
  191 + // 磁盘缓存none
  192 + strategy: new NONE()
  193 + };
  194 + return imageKnifeOption
  195 + }
  196 +
167 private getBottomIcon(navItem: BottomNavDTO, isSelect: boolean): string | Resource { 197 private getBottomIcon(navItem: BottomNavDTO, isSelect: boolean): string | Resource {
168 if (!navItem) { 198 if (!navItem) {
169 return '' 199 return ''
@@ -176,10 +206,10 @@ export struct BottomNavigationComponent { @@ -176,10 +206,10 @@ export struct BottomNavigationComponent {
176 // 获取常规icon 206 // 获取常规icon
177 icon = isSelect ? navItem.iconC : navItem.icon 207 icon = isSelect ? navItem.iconC : navItem.icon
178 } 208 }
179 - if (StringUtils.isEmpty(icon) || icon.includes('.pag')) {  
180 - // 兜底,获取预置的本地icon  
181 - return this.getBottomLocalIcon(navItem, isSelect)  
182 - } 209 + // if (StringUtils.isEmpty(icon) || icon.includes('.pag')) {
  210 + // // 兜底,获取预置的本地icon
  211 + // return this.getBottomLocalIcon(navItem, isSelect)
  212 + // }
183 return icon 213 return icon
184 } 214 }
185 215
@@ -17,6 +17,7 @@ import { TrackingModule } from 'wdTracking/Index' @@ -17,6 +17,7 @@ import { TrackingModule } from 'wdTracking/Index'
17 import { JSON } from '@kit.ArkTS' 17 import { JSON } from '@kit.ArkTS'
18 import app from '@system.app' 18 import app from '@system.app'
19 import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index' 19 import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index'
  20 +import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife'
20 21
21 const TAG = "[StartupManager]" 22 const TAG = "[StartupManager]"
22 23
@@ -58,6 +59,14 @@ export class StartupManager { @@ -58,6 +59,14 @@ export class StartupManager {
58 HostManager.changeHost(spHostUrl as HostEnum) 59 HostManager.changeHost(spHostUrl as HostEnum)
59 } 60 }
60 61
  62 + // 初始化全局ImageKnife
  63 + ImageKnife.with(this.context);
  64 + let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife()
  65 + if (imageKnife != undefined) {
  66 + //设置全局内存缓存大小张数
  67 + imageKnife.setLruCacheSize(100, 100 * 1204 * 1024)
  68 + }
  69 +
61 // 友盟预初始化 70 // 友盟预初始化
62 this.preInitUmentStat() 71 this.preInitUmentStat()
63 72