Bladeren bron

list组件

徐勤民 2 maanden geleden
bovenliggende
commit
4130519353
5 gewijzigde bestanden met toevoegingen van 82 en 19 verwijderingen
  1. 1 0
      Index.ets
  2. 22 18
      README.md
  3. 2 0
      src/main/ets/ContextConfig.ets
  4. 56 0
      src/main/ets/view/RefreshView.ets
  5. 1 1
      src/main/ets/view/SafeView.ets

+ 1 - 0
Index.ets

@@ -47,6 +47,7 @@ export { WindowHelper } from './src/main/ets/utils/WindowHelper'
  */
 export { LoadingView } from './src/main/ets/view/LoadingView'
 export { SafeView } from './src/main/ets/view/SafeView'
+export { RefreshView } from './src/main/ets/view/RefreshView'
 /**
  * 自定义view
  */

+ 22 - 18
README.md

@@ -4,6 +4,28 @@
 ohpm install @szyx/sdk_base
 ```
 
+## 0.初始化
+> 在UIAbility的onWindowStageCreate方法中初始化该方法
+
+```tsx
+// 初始化
+import { WindowHelper } from '@szyx/sdk_base';
+export default class AppAbility extends UIAbility {
+    onWindowStageCreate(windowStage: window.WindowStage): void {
+
+        windowStage.loadContent('pages/Index', (err) => {
+            if (err.code) {
+                hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
+                return;
+            }
+            WindowHelper.windowClass = windowStage.getMainWindowSync()
+        });
+        // 这行代码
+        GlobalContext.setContext(this.context)
+    }
+}
+```
+
 ## 1.[utils](./src/main/ets/utils)
 
 ### 1.1.[AppStorageHelper](./src/main/ets/utils/AppStorageHelper.ets)
@@ -330,24 +352,6 @@ WindowHelper.close()
 
 ### 5.2.设置沉浸式相关
 
-```tsx
-// 初始化
-import { WindowHelper } from '@szyx/sdk_base';
-export default class AppAbility extends UIAbility {
-    onWindowStageCreate(windowStage: window.WindowStage): void {
-
-        windowStage.loadContent('pages/Index', (err) => {
-            if (err.code) {
-                hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
-                return;
-            }
-            WindowHelper.windowClass = windowStage.getMainWindowSync()
-        });
-        GlobalContext.setContext(this.context)
-    }
-}
-```
-
 ```tsx
 // 需要的界面
 // 设置是否全屏

+ 2 - 0
src/main/ets/ContextConfig.ets

@@ -3,6 +3,7 @@
  */
 
 import type common from '@ohos.app.ability.common';
+import { WindowHelper } from './utils/WindowHelper';
 
 declare namespace globalThis {
   let _brushEngineContext: common.UIAbilityContext;
@@ -15,6 +16,7 @@ export class GlobalContext {
 
   static setContext(context: common.UIAbilityContext): void {
     globalThis._brushEngineContext = context;
+    WindowHelper.windowClass = context.windowStage.getMainWindowSync()
   }
 }
 

+ 56 - 0
src/main/ets/view/RefreshView.ets

@@ -0,0 +1,56 @@
+import { ToolsHelper } from '../utils/ToolsHelper'
+
+type ItemType = (string | number | Object)
+
+@Preview
+@Component
+export struct RefreshView {
+  @Prop isLoading: boolean
+  @Prop data: ItemType[]
+
+  @Builder customBuilder() {}
+  // 使用父组件@Builder装饰的方法初始化子组件@BuilderParam
+  @BuilderParam customBuilderParam: (item:string) => void = this.customBuilder;
+
+  build() {
+
+    Refresh({ refreshing: $$this.isLoading }) {
+      List() {
+        ForEach(this.data ?? [], (item: string) => {
+          ListItem() {
+            this.customBuilderParam(item)
+          }
+          .backgroundColor('blue')
+        }, (index: number) => index.toString())
+      }
+      .onScrollStart(() => {
+        ToolsHelper.log('onScrollStart')
+      })
+      .onScrollStop(() => {
+        ToolsHelper.log('onScrollStop')
+      })
+      .onTouch((event: TouchEvent) => {
+        const e1 = event.touches[0]
+        ToolsHelper.log(`onTouch ${event.type}-${e1.x.toString()}-${e1.y.toString()}`)
+      })
+      .onScrollIndex((first: number, last: number) => {
+        ToolsHelper.log(`${first.toString()}-${last.toString()}`)
+      })
+      .width('100%')
+      .height('100%')
+      .alignListItem(ListItemAlign.Center)
+      .scrollBar(BarState.Off)
+    }.width('100%')
+    .backgroundColor('red')
+    .height('100%')
+    .onStateChange((refreshStatus: RefreshStatus) => {
+      ToolsHelper.log('Refresh onStatueChange state is ' + refreshStatus)
+    })
+    .onRefreshing(() => {
+      setTimeout(() => {
+        this.isLoading = false
+      }, 2000)
+      ToolsHelper.log('onRefreshing test')
+    })
+  }
+}

+ 1 - 1
src/main/ets/view/SafeView.ets

@@ -80,7 +80,7 @@ export struct SafeView {
               }).visibility(!this.hideBack ? Visibility.Visible : Visibility.None)
           }.width(110)
 
-          Text(`${this.titleText}`)
+          Text(this.titleText ?? '')
             .maxLines(1)
             .fontColor('#11102C')
             .fontSize(16)