修复系统界面息屏失焦,表冠失效
authorxue <2144439972@qq.com>
Thu, 5 Feb 2026 03:38:23 +0000 (11:38 +0800)
committerxue <2144439972@qq.com>
Thu, 5 Feb 2026 03:38:23 +0000 (11:38 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemView.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemPresenter.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemView.cpp

index d6eb50d..77a12d7 100644 (file)
@@ -94,6 +94,8 @@ namespace OHOS
         bool CheckViewParam(int16_t hideView, int16_t showView);\r
         void ChangeView(int16_t hideView, int16_t showView);\r
         UIScrollView *GetSystemScrollView(int ViewId);\r
+        /** 息屏再亮屏后表冠失效时,为当前显示的滚动视图重新申请焦点(含系统主界面、关于手表等所有 subview) */\r
+        void RequestFocusForCurrentView();\r
 \r
     private:\r
         SystemAboutTheWatchView *p_SystemAboutTheWatchView{nullptr};     // 关于手表\r
@@ -121,6 +123,7 @@ namespace OHOS
         UIImageView *NeedToUpdateImage{nullptr}; // 提示需要系统更新的icon图片\r
         UIImageView *temp{nullptr};\r
         bool viewInitStatus{false};\r
+        int16_t currentShowViewId_{SYSTEMVIEW};  // 当前显示的 subview,息屏亮屏后用于恢复表冠焦点\r
     };\r
 } // namespace OHOS\r
 \r
index 1bf344a..c1c990e 100644 (file)
@@ -52,6 +52,10 @@ namespace OHOS
     void SystemPresenter::OnResume()\r
     {\r
         RootView::GetInstance()->SetOnKeyActListener(this);\r
+        SystemView *p_SystemView = SystemView::GetInstance();\r
+        if (p_SystemView != nullptr) {\r
+            p_SystemView->RequestFocusForCurrentView(); \r
+        }\r
     }\r
 \r
     static uint32_t time = 0;\r
index 7275990..5f26afa 100644 (file)
@@ -353,12 +353,22 @@ namespace OHOS
         {\r
             NeedToUpdateImageinit();\r
         }\r
+        currentShowViewId_ = SYSTEMVIEW;\r
         AddViewToRootContainer(SystemScrollView[SYSTEMVIEW]);\r
     }\r
 \r
-   \r
+    void SystemView::RequestFocusForCurrentView()\r
+    {\r
+        // 系统主界面、关于手表等任意当前 subview 息屏亮屏后恢复表冠焦点\r
+        if (currentShowViewId_ >= 0 && currentShowViewId_ < MAX_SYSTEMVIEWID &&\r
+            SystemScrollView[currentShowViewId_] != nullptr) {\r
+            SystemScrollView[currentShowViewId_]->RequestFocus();\r
+        }\r
+    }\r
 \r
 \r
+   \r
+\r
     // 0.跳转到系统视图,其他视图都市通过这个视图跳转\r
     bool SystemView::ChangeToSystemView(int16_t thisView)\r
     {\r
@@ -542,6 +552,10 @@ namespace OHOS
         SystemScrollView[hideView]->SetVisible(false);\r
         ClickFunc(showView);\r
         SystemScrollView[showView]->SetVisible(true);\r
+        currentShowViewId_ = showView;\r
+        if (SystemScrollView[showView] != nullptr) {\r
+            SystemScrollView[showView]->RequestFocus();\r
+        }\r
         Draw();\r
     }\r
 \r