Skip to content

Commit b735db0

Browse files
authored
fix: removes the TurboModule conversion from vp to px (#59)
Signed-off-by: tyBrave <tianyong21@h-partners.com>
1 parent ac1cd5b commit b735db0

16 files changed

+44
-181
lines changed
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
/**
2+
* Use these variables when you tailor your ArkTS code. They must be of the const type.
3+
*/
4+
export const HAR_VERSION = '0.6.7-0.2.15';
5+
export const BUILD_MODE_NAME = 'release';
6+
export const DEBUG = false;
7+
export const TARGET_NAME = 'default';
8+
9+
/**
10+
* BuildProfile Class is used only for compatibility purposes.
11+
*/
112
export default class BuildProfile {
2-
static readonly HAR_VERSION = '0.6.7-0.2.15';
3-
static readonly BUILD_MODE_NAME = 'debug';
4-
static readonly DEBUG = true;
5-
static readonly TARGET_NAME = 'default';
13+
static readonly HAR_VERSION = HAR_VERSION;
14+
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
15+
static readonly DEBUG = DEBUG;
16+
static readonly TARGET_NAME = TARGET_NAME;
617
}

harmony/smart_refresh_layout/src/main/cpp/PullToRefreshNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
namespace rnoh {
77
PullToRefreshNode::PullToRefreshNode()
88
: ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_COLUMN)),
9-
m_headerArkUINodeHandle(nullptr), m_listArkUINodeHandle(nullptr), m_pullToRefreshNodeDelegate(nullptr) {
10-
}
9+
m_headerArkUINodeHandle(nullptr), m_listArkUINodeHandle(nullptr), m_pullToRefreshNodeDelegate(nullptr),
10+
refreshConfigurator{std::make_shared<PullToRefreshConfigurator>()}{}
1111

1212
PullToRefreshNode::~PullToRefreshNode() {}
1313
void PullToRefreshNode::setPullToRefreshNodeDelegate(PullToRefreshNodeDelegate *pullToRefreshNodeDelegate) {
@@ -47,9 +47,9 @@ namespace rnoh {
4747
NativeNodeApi::getInstance()->setAttribute(m_headerArkUINodeHandle, NODE_HEIGHT, &heightItem);
4848
}
4949

50-
void PullToRefreshNode::setEnableRefresh(bool enable) { refreshConfigurator.setHasRefresh(enable); }
51-
void PullToRefreshNode::setMaxTranslate(float maxHeight) { refreshConfigurator.setMaxTranslate(maxHeight); }
52-
void PullToRefreshNode::setSensitivity(float setSensitivity) { refreshConfigurator.setSensitivity(setSensitivity); }
50+
void PullToRefreshNode::setEnableRefresh(bool enable) { refreshConfigurator->setHasRefresh(enable); }
51+
void PullToRefreshNode::setMaxTranslate(float maxHeight) { refreshConfigurator->setMaxTranslate(maxHeight); }
52+
void PullToRefreshNode::setSensitivity(float setSensitivity) { refreshConfigurator->setSensitivity(setSensitivity); }
5353
void PullToRefreshNode::setHeaderBackgroundColor(facebook::react::SharedColor const &color) {
5454
uint32_t colorValue1 = *color;
5555
ArkUI_NumberValue preparedColorValue1[] = {{.u32 = colorValue1}};

harmony/smart_refresh_layout/src/main/cpp/PullToRefreshNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace rnoh {
2525
ArkUI_NodeHandle m_headerArkUINodeHandle;
2626
ArkUI_NodeHandle m_listArkUINodeHandle;
2727
PullToRefreshNodeDelegate *m_pullToRefreshNodeDelegate;
28-
PullToRefreshConfigurator refreshConfigurator{PullToRefreshConfigurator()};
28+
std::shared_ptr<PullToRefreshConfigurator> refreshConfigurator;
2929

3030
public:
3131
PullToRefreshNode();
@@ -41,7 +41,7 @@ namespace rnoh {
4141
void setEnableRefresh(bool enable);
4242
void setMaxTranslate(float maxHeight);
4343
void setHeaderBackgroundColor(facebook::react::SharedColor const &color);
44-
PullToRefreshConfigurator getPullToRefreshConfigurator() { return refreshConfigurator; }
44+
PullToRefreshConfigurator getPullToRefreshConfigurator() { return *refreshConfigurator; }
4545
void onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs) override;
4646
void setSensitivity(float setSensitivity);
4747
};

harmony/smart_refresh_layout/src/main/cpp/RNCAnyHeaderComponentInstance.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ namespace rnoh {
3535
}
3636
}
3737
}
38-
auto rnInstancePtr = this->m_deps->rnInstance.lock();
39-
if (rnInstancePtr != nullptr) {
40-
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
41-
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
42-
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
43-
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {childHeight});
44-
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
45-
}
38+
double pointScaleFactor = getLayoutMetrics().pointScaleFactor;
39+
m_stackNode.setLayoutRect({0, 0},
40+
{SmartUtils::vp2px(pointScaleFactor, getLayoutMetrics().frame.size.width),
41+
SmartUtils::vp2px(pointScaleFactor, childHeight)},
42+
1.0);
4643
}
4744

4845
void RNCAnyHeaderComponentInstance::onPropsChanged(SharedConcreteProps const &props) {

harmony/smart_refresh_layout/src/main/cpp/RNCDefaultHeaderComponentInstance.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,11 @@ namespace rnoh {
7070
return SmartUtils::parseColor(primaryColor);
7171
}
7272
void RNCDefaultHeaderComponentInstance::finalizeUpdates() {
73-
auto rnInstancePtr = this->m_deps->rnInstance.lock();
74-
if (rnInstancePtr != nullptr) {
75-
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
76-
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
77-
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
78-
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {60});
79-
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
80-
}
73+
m_stackNode.setLayoutRect(
74+
{0, 0},
75+
{SmartUtils::vp2px(getLayoutMetrics().pointScaleFactor, getLayoutMetrics().frame.size.width),
76+
SmartUtils::vp2px(getLayoutMetrics().pointScaleFactor, 60)},
77+
1.0);
8178
m_stackNode.setAlignment(ARKUI_ALIGNMENT_BOTTOM);
8279
}
8380

harmony/smart_refresh_layout/src/main/cpp/RNCMaterialHeaderComponentInstance.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,10 @@ namespace rnoh {
105105
}
106106

107107
void RNCMaterialHeaderComponentInstance::finalizeUpdates() {
108-
auto rnInstancePtr = this->m_deps->rnInstance.lock();
109-
if (rnInstancePtr != nullptr) {
110-
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
111-
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
112-
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
113-
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {60});
114-
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
115-
}
108+
m_stackNode.setLayoutRect({0, 0},
109+
{getLayoutMetrics().pointScaleFactor * getLayoutMetrics().frame.size.width,
110+
getLayoutMetrics().pointScaleFactor * 60},
111+
1.0);
116112
m_stackNode.setAlignment(ARKUI_ALIGNMENT_BOTTOM);
117113
}
118114

harmony/smart_refresh_layout/src/main/cpp/RNCSmartRefreshTurboModule.cpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

harmony/smart_refresh_layout/src/main/cpp/RNCSmartRefreshTurboModule.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

harmony/smart_refresh_layout/src/main/cpp/RNCStoreHouseHeaderComponentInstance.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "RNCStoreHouseHeaderComponentInstance.h"
88
#include "RNOH/arkui/NativeNodeApi.h"
9+
#include "SmartUtils.h"
910

1011
namespace rnoh {
1112

@@ -24,14 +25,7 @@ void RNCStoreHouseHeaderComponentInstance::onChildRemoved(ComponentInstance::Sha
2425
};
2526

2627
float RNCStoreHouseHeaderComponentInstance::getVp2Px(float v) {
27-
auto rnInstancePtr = this->m_deps->rnInstance.lock();
28-
if (rnInstancePtr != nullptr) {
29-
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
30-
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
31-
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {v});
32-
return result["values"].asDouble();
33-
}
34-
return -1;
28+
return SmartUtils::vp2px(getLayoutMetrics().pointScaleFactor, v);;
3529
}
3630
facebook::react::SharedColor RNCStoreHouseHeaderComponentInstance::GetPrimaryColor() { return -1; };
3731
void RNCStoreHouseHeaderComponentInstance::onHeaderMove(float dur) { m_storeHouseNode.setProgress(dur); };

harmony/smart_refresh_layout/src/main/cpp/SmartRefreshLayoutComponentInstance.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ namespace rnoh {
136136
if (state == IS_FREE || state == IS_PULL_DOWN_1 || state == IS_PULL_DOWN_2 || state == IS_PULL_UP_1 ||
137137
state == IS_PULL_UP_2) {
138138
auto maxTranslate = m_pullToRefreshNode.getPullToRefreshConfigurator().getMaxTranslate();
139-
auto loadImgHeight = m_pullToRefreshNode.getPullToRefreshConfigurator().getLoadImgHeight();
140-
auto refreshHeight = m_pullToRefreshNode.getPullToRefreshConfigurator().getRefreshHeight();
141139
touchYNew = offsetY;
142140
if (!isComponentTop()) {
143141
return;
@@ -168,7 +166,6 @@ namespace rnoh {
168166

169167
void SmartRefreshLayoutComponentInstance::onActionEnd() {
170168
auto maxTranslate = m_pullToRefreshNode.getPullToRefreshConfigurator().getMaxTranslate();
171-
auto refreshAnimDuration = m_pullToRefreshNode.getPullToRefreshConfigurator().getRefreshAnimDuration();
172169
if (trYTop > 0) {
173170
if (state == IS_FREE || state == IS_PULL_DOWN_1 || state == IS_PULL_DOWN_2) {
174171
if (trYTop / maxTranslate < 0.5) {
@@ -226,7 +223,7 @@ namespace rnoh {
226223
return;
227224
}
228225
if (animation == nullptr) {
229-
animation = new Animation();
226+
animation = std::make_shared<Animation>();
230227
}
231228
animation->SetAnimationParams(
232229
static_cast<std::chrono::milliseconds>(duration), start, target, [this, &target](double value) {
@@ -245,7 +242,6 @@ namespace rnoh {
245242
ptr->m_pullToRefreshNode.markDirty();
246243
ptr->changeStatus();
247244
if (ptr->animation && ptr->animation->GetAnimationStatus() != ANIMATION_FREE) {
248-
delete (ptr->animation);
249245
ptr->animation = nullptr;
250246
}
251247
}

harmony/smart_refresh_layout/src/main/cpp/SmartRefreshLayoutComponentInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace rnoh {
4040
float oldHeaderTop{0.0};
4141
int32_t downY{0}; // first down touch on Y
4242
int32_t offsetY{0}; // pan offset on Y
43-
Animation *animation{nullptr};
43+
std::shared_ptr<Animation> animation{nullptr};
4444
void setOtherHeaderDelegate();
4545

4646
public:

harmony/smart_refresh_layout/src/main/cpp/SmartRefreshLayoutPackage.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "RNCDefaultHeaderComponentInstance.h"
3636
#include "RNCClassicsHeaderComponentInstance.h"
3737
#include "RNCMaterialHeaderComponentInstance.h"
38-
#include "RNCSmartRefreshTurboModule.h"
3938
#include "RNCStoreHouseHeaderComponentInstance.h"
4039
#include "RNCStoreHouseHeaderJSIBinder.h"
4140
#include "RNCStoreHouseHeaderNapiBinder.h"
@@ -69,28 +68,14 @@ class SmartRefreshLayoutPackageComponentInstanceFactoryDelegate : public Compone
6968
}
7069
};
7170

72-
class RNCSmartRefreshFactoryDelegate : public TurboModuleFactoryDelegate {
73-
public:
74-
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
75-
if (name == "RNCSmartRefreshContext") {
76-
return std::make_shared<RNCSmartRefreshTurboModule>(ctx, name);
77-
}
78-
return nullptr;
79-
};
80-
};
81-
8271
class SmartRefreshLayoutPackage : public Package {
8372
public:
8473
SmartRefreshLayoutPackage(Package::Context ctx) : Package(ctx) {}
8574

8675
ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override {
8776
return std::make_shared<SmartRefreshLayoutPackageComponentInstanceFactoryDelegate>();
8877
}
89-
90-
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
91-
return std::make_unique<RNCSmartRefreshFactoryDelegate>();
92-
}
93-
78+
9479
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
9580
return {
9681
facebook::react::concreteComponentDescriptorProvider<

harmony/smart_refresh_layout/src/main/cpp/SmartUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ class SmartUtils {
3030
}
3131
return facebook::react::colorFromComponents({red, green, blue, alpha});
3232
}
33+
34+
// NOTE: ArkUI translation is in `px` units, while React Native uses `vp`
35+
static double vp2px(double pointScaleFactor, double value) { return pointScaleFactor * value; }
3336
};
3437
#endif // HARMONY_ANIMATION_H

harmony/smart_refresh_layout/src/main/ets/SmartRefreshPackage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424

2525
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
2626
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
27-
import { SmartRefreshTurboModule } from './SmartRefreshTurboModule';
2827

2928
class SmartRefreshTurboModulesFactory extends TurboModulesFactory {
3029
createTurboModule(name: string): TurboModule | null {
31-
if (name === 'RNCSmartRefreshContext') {
32-
return new SmartRefreshTurboModule(this.ctx);
33-
}
3430
return null;
3531
}
3632

harmony/smart_refresh_layout/src/main/ets/SmartRefreshTurboModule.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

harmony/smart_refresh_layout/ts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
* SOFTWARE.
2323
*/
2424

25-
export * from "./src/main/ets/SmartRefreshTurboModule"
2625
export * from "./src/main/ets/SmartRefreshPackage"

0 commit comments

Comments
 (0)