Skip to content

Commit 502a345

Browse files
committed
feat(ohos): adapt list for desktop device
1 parent c0b3ebe commit 502a345

File tree

7 files changed

+127
-7
lines changed

7 files changed

+127
-7
lines changed

framework/ohos/src/main/cpp/impl/connector/src/setting_napi.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "oh_napi/ark_ts.h"
2727
#include "footstone/check.h"
2828
#include "footstone/logging.h"
29+
#include "renderer/utils/hr_device_utils.h"
2930
#include "renderer/utils/hr_pixel_utils.h"
3031

3132
namespace hippy {
@@ -83,11 +84,18 @@ static napi_value SetFontWeightScale(napi_env env, napi_callback_info info) {
8384
return arkTs.GetUndefined();
8485
}
8586

87+
static napi_value SetDesktop(napi_env env, napi_callback_info info) {
88+
HRDeviceUtils::SetDesktop();
89+
ArkTS arkTs(env);
90+
return arkTs.GetUndefined();
91+
}
92+
8693
REGISTER_OH_NAPI("Setting", "Setting_SetFlags", SetFlags)
8794
REGISTER_OH_NAPI("Setting", "Setting_SetDensity", SetDensity)
8895
REGISTER_OH_NAPI("Setting", "Setting_SetDensityScale", SetDensityScale)
8996
REGISTER_OH_NAPI("Setting", "Setting_SetFontSizeScale", SetFontSizeScale)
9097
REGISTER_OH_NAPI("Setting", "Setting_SetFontWeightScale", SetFontWeightScale)
98+
REGISTER_OH_NAPI("Setting", "Setting_SetDesktop", SetDesktop)
9199

92100
}
93101
}

framework/ohos/src/main/cpp/impl/renderer/native/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set(SOURCE_SET
7878
src/uimanager/hr_keyboard_manager.cc
7979
src/utils/hr_event_utils.cc
8080
src/utils/hr_convert_utils.cc
81+
src/utils/hr_device_utils.cc
8182
src/utils/hr_pixel_utils.cc
8283
src/utils/hr_text_convert_utils.cc
8384
src/utils/hr_url_utils.cc
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* Tencent is pleased to support the open source community by making
4+
* Hippy available.
5+
*
6+
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
7+
* All rights reserved.
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*
21+
*/
22+
23+
#pragma once
24+
25+
namespace hippy {
26+
inline namespace render {
27+
inline namespace native {
28+
29+
class HRDeviceUtils {
30+
public:
31+
inline static void SetDesktop() {
32+
isDesktop_ = true;
33+
}
34+
35+
inline static bool IsDesktop() {
36+
return isDesktop_;
37+
}
38+
39+
private:
40+
static bool isDesktop_;
41+
};
42+
43+
} // namespace native
44+
} // namespace render
45+
} // namespace hippy

framework/ohos/src/main/cpp/impl/renderer/native/src/components/list_view.cc

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "renderer/components/refresh_wrapper_view.h"
2626
#include "renderer/dom_node/hr_node_props.h"
2727
#include "renderer/utils/hr_convert_utils.h"
28+
#include "renderer/utils/hr_device_utils.h"
2829
#include "renderer/utils/hr_event_utils.h"
2930
#include "renderer/utils/hr_pixel_utils.h"
3031
#include "renderer/utils/hr_value_utils.h"
@@ -333,6 +334,19 @@ void ListView::OnScrollStop() {
333334
if (onScrollEventEnable_) {
334335
EmitScrollEvent(HREventUtils::EVENT_SCROLLER_ON_SCROLL);
335336
}
337+
338+
if (HRDeviceUtils::IsDesktop()) {
339+
if (footerView_ && pullAction_ == ScrollAction::PullFooter) {
340+
if (footerViewFullVisible_) {
341+
HREventUtils::SendComponentEvent(footerView_->GetCtx(), footerView_->GetTag(),
342+
HREventUtils::EVENT_PULL_FOOTER_RELEASED, nullptr);
343+
} else {
344+
auto lastIndex = static_cast<int32_t>(children_.size()) - 1;
345+
listNode_->ScrollToIndex(lastIndex - 1 - (hasPullHeader_? 1 : 0), true, ARKUI_SCROLL_ALIGNMENT_END);
346+
}
347+
pullAction_ = ScrollAction::None;
348+
}
349+
}
336350
}
337351

338352
void ListView::OnReachStart() {
@@ -346,11 +360,13 @@ void ListView::OnReachEnd() {
346360

347361
void ListView::OnTouch(int32_t actionType, const HRPosition &screenPosition) {
348362
BaseView::OnTouch(actionType, screenPosition);
349-
350-
if (actionType == UI_TOUCH_EVENT_ACTION_DOWN || actionType == UI_TOUCH_EVENT_ACTION_MOVE) {
351-
CheckBeginDrag();
352-
} else if (actionType == UI_TOUCH_EVENT_ACTION_UP || actionType == UI_TOUCH_EVENT_ACTION_CANCEL) {
353-
CheckEndDrag();
363+
364+
if (!HRDeviceUtils::IsDesktop()) {
365+
if (actionType == UI_TOUCH_EVENT_ACTION_DOWN || actionType == UI_TOUCH_EVENT_ACTION_MOVE) {
366+
CheckBeginDrag();
367+
} else if (actionType == UI_TOUCH_EVENT_ACTION_UP || actionType == UI_TOUCH_EVENT_ACTION_CANCEL) {
368+
CheckEndDrag();
369+
}
354370
}
355371
}
356372

@@ -614,15 +630,24 @@ void ListView::CheckPullOnItemVisibleAreaChange(int32_t index, bool isVisible, f
614630
auto lastIndex = static_cast<int32_t>(children_.size()) - 1;
615631
if (footerView_ && index == lastIndex) {
616632
if (isVisible) {
617-
if (isDragging_) {
633+
if (HRDeviceUtils::IsDesktop()) {
618634
pullAction_ = ScrollAction::PullFooter;
619635
if (currentRatio >= 1.0) {
620636
footerViewFullVisible_ = true;
621637
} else {
622638
footerViewFullVisible_ = false;
623639
}
624640
} else {
625-
listNode_->ScrollToIndex(lastIndex - 1 - (hasPullHeader_? 1 : 0), true, ARKUI_SCROLL_ALIGNMENT_END);
641+
if (isDragging_) {
642+
pullAction_ = ScrollAction::PullFooter;
643+
if (currentRatio >= 1.0) {
644+
footerViewFullVisible_ = true;
645+
} else {
646+
footerViewFullVisible_ = false;
647+
}
648+
} else {
649+
listNode_->ScrollToIndex(lastIndex - 1 - (hasPullHeader_? 1 : 0), true, ARKUI_SCROLL_ALIGNMENT_END);
650+
}
626651
}
627652
} else {
628653
footerViewFullVisible_ = false;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*
3+
* Tencent is pleased to support the open source community by making
4+
* Hippy available.
5+
*
6+
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
7+
* All rights reserved.
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*
21+
*/
22+
23+
#include "renderer/utils/hr_device_utils.h"
24+
25+
namespace hippy {
26+
inline namespace render {
27+
inline namespace native {
28+
29+
bool HRDeviceUtils::isDesktop_ = false;
30+
31+
} // namespace native
32+
} // namespace render
33+
} // namespace hippy

framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
1919
*/
20+
import deviceInfo from '@ohos.deviceInfo';
2021
import { HippyLibrary } from '../hippy_library/HippyLibrary';
2122
import { PixelUtil } from "../support/utils/PixelUtil";
2223
import { NativeRenderContext } from '../renderer_native/NativeRenderContext';
@@ -97,6 +98,12 @@ export function createHippyEngine(params: EngineInitParams): HippyEngine {
9798
PixelUtil.doInitDensity()
9899
LogUtils.enableDebugLog(params.enableLog)
99100
params.libHippy?.Setting_SetFlags(params.enableUpdateAnimLog);
101+
102+
let deviceType: string = deviceInfo.deviceType;
103+
if (deviceType === "2in1") {
104+
params.libHippy?.Setting_SetDesktop();
105+
}
106+
100107
return new HippyEngineManagerImpl(params)
101108
}
102109

framework/ohos/src/main/ets/hippy_library/HippyLibrary.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export interface HippyLibrary {
143143
Setting_SetDensityScale(densityScale: number): void;
144144
Setting_SetFontSizeScale(fontSizeScale: number): void;
145145
Setting_SetFontWeightScale(fontWeightScale: number): void;
146+
Setting_SetDesktop(): void;
146147

147148
// main线程使用
148149
WorkerManager_InitWModuleManager(notifyMainThreadFunction: (

0 commit comments

Comments
 (0)