From d2c8e9a1bc8e8f2d8381ee62ba496fd8ffa1faa2 Mon Sep 17 00:00:00 2001 From: zichenyang Date: Sat, 22 Feb 2025 09:46:26 +0800 Subject: [PATCH] fix: Button onPress cannot be triggered using keyboard space Signed-off-by: zichenyang --- .../Libraries/Components/Button/Button.harmony.js | 4 ++-- .../src/main/cpp/RNOH/CppComponentInstance.h | 8 ++++++++ .../src/main/cpp/RNOH/arkui/ArkUINode.cpp | 10 ++++++++++ .../src/main/cpp/RNOH/arkui/ArkUINode.h | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/react-native-harmony/Libraries/Components/Button/Button.harmony.js b/react-native-harmony/Libraries/Components/Button/Button.harmony.js index 2e990a9c..98f92d33 100644 --- a/react-native-harmony/Libraries/Components/Button/Button.harmony.js +++ b/react-native-harmony/Libraries/Components/Button/Button.harmony.js @@ -379,8 +379,8 @@ class Button extends React.Component { testID={testID} disabled={disabled} onPress={onPress} - touchSoundDisabled={touchSoundDisabled}> - + touchSoundDisabled={touchSoundDisabled}> + {formattedTitle} diff --git a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/CppComponentInstance.h b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/CppComponentInstance.h index c83633d9..8a920e45 100644 --- a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/CppComponentInstance.h +++ b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/CppComponentInstance.h @@ -502,6 +502,14 @@ class CppComponentInstance : public ComponentInstance, this->getLocalRootArkUINode().setRenderGroup(m_rawProps.needsOffscreenAlphaCompositing); } + if (props->rawProps.count("focusable") > 0) { + if (!m_props || + props->rawProps["focusable"].asBool() != + m_props->rawProps["focusable"].asBool()) { + getLocalRootArkUINode().setFocusable(props->rawProps["focusable"].asBool()); + } + } + this->getLocalRootArkUINode().setId(getIdFromProps(props)); m_oldBorderMetrics = props->resolveBorderMetrics(this->m_layoutMetrics); diff --git a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.cpp b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.cpp index 54096b05..c0b01612 100644 --- a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.cpp +++ b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.cpp @@ -771,6 +771,16 @@ ArkUINode& ArkUINode::setZIndex(float index) { return *this; } +ArkUINode& ArkUINode::setFocusable(bool focusable) { + int32_t focusableValue = focusable; + ArkUI_NumberValue preparedFocusable[] = {{.i32 = focusableValue}}; + ArkUI_AttributeItem focusItem = { + preparedFocusable, sizeof(preparedFocusable) / sizeof(ArkUI_NumberValue)}; + maybeThrow(NativeNodeApi::getInstance()->setAttribute( + m_nodeHandle, NODE_FOCUSABLE, &focusItem)); + return *this; +} + ArkUINode& ArkUINode::setRenderGroup(bool flag) { ArkUI_NumberValue value[] = {{.i32 = (int32_t)flag}}; ArkUI_AttributeItem item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)}; diff --git a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.h b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.h index 9744ddbd..bf4a9b37 100644 --- a/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.h +++ b/tester/harmony/react_native_openharmony/src/main/cpp/RNOH/arkui/ArkUINode.h @@ -144,6 +144,7 @@ class ArkUINode { virtual ArkUINode& setRenderGroup(bool flag); virtual ArkUINode& setDirection(ArkUI_Direction direction); virtual ArkUINode& setZIndex(float index); + virtual ArkUINode& setFocusable(bool focusable); virtual ArkUINode& resetAccessibilityText(); -- Gitee