Skip to content

Commit 0f54098

Browse files
Merge pull request #22 from tyBrave/sig
fix:solve question setSize method does not work causing a blank header
2 parents 2a81e11 + 23f24ba commit 0f54098

File tree

8 files changed

+217
-11
lines changed

8 files changed

+217
-11
lines changed

harmony/smart_refresh_layout/index.ets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
*/
1515
export * from "./src/main/ets/SmartRefreshControl"
1616
export * from "./src/main/ets/RNCAnyHeader"
17-
export * from "./src/main/ets/RNCDefaultHeader"
17+
export * from "./src/main/ets/RNCDefaultHeader"
18+
export * from './ts'

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ namespace rnoh {
2525

2626
void RNCAnyHeaderComponentInstance::finalizeUpdates() {
2727
std::vector<ComponentInstance::Shared> child = getChildren();
28-
float childHeight = 0.0;
29-
for (ComponentInstance::Shared c : child) {
30-
if (c) {
31-
auto height = c->getLayoutMetrics().frame.size.height;
32-
if (height>childHeight) {
33-
childHeight = height;
34-
}
35-
}
36-
}
37-
m_stackNode.setSize(facebook::react::Size({ getLayoutMetrics().frame.size.width, childHeight}));
28+
float childHeight = 0.0;
29+
for (ComponentInstance::Shared c : child) {
30+
if (c) {
31+
auto height = c->getLayoutMetrics().frame.size.height;
32+
if (height>childHeight) {
33+
childHeight = height;
34+
}
35+
}
36+
}
37+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
38+
if (rnInstancePtr != nullptr) {
39+
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
40+
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
41+
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});;
42+
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {childHeight});
43+
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
44+
}
3845
}
3946

4047
} // namespace rnoh
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#pragma once
26+
27+
#include <ReactCommon/TurboModule.h>
28+
#include "RNOH/ArkTSTurboModule.h"
29+
30+
namespace rnoh {
31+
32+
class JSI_EXPORT RNCSmartRefreshTurboModule : public ArkTSTurboModule {
33+
public:
34+
RNCSmartRefreshTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
35+
};
36+
37+
} // namespace rnoh
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include "RNCSmartRefreshTurbomodule.h"
26+
27+
using namespace rnoh;
28+
using namespace facebook;
29+
30+
static jsi::Value __hostFunction_RNCSmartRefreshTurboModule_cvp2px(jsi::Runtime &rt,
31+
react::TurboModule &turboModule,
32+
const jsi::Value *args, size_t count)
33+
{
34+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "cvp2px", args, count);
35+
}
36+
37+
RNCSmartRefreshTurboModule::RNCSmartRefreshTurboModule(const ArkTSTurboModule::Context ctx,
38+
const std::string name)
39+
: ArkTSTurboModule(ctx, name)
40+
{
41+
methodMap_["cvp2px"] = MethodMetadata{0, __hostFunction_RNCSmartRefreshTurboModule_cvp2px};
42+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "RNCDefaultHeaderComponentInstance.h"
3636
#include "RNCClassicsHeaderComponentInstance.h"
3737
#include "RNCMaterialHeaderComponentInstance.h"
38+
#include "RNCSmartRefreshTurboModule.h"
3839

3940
namespace rnoh {
4041

@@ -62,6 +63,16 @@ namespace rnoh {
6263
}
6364
};
6465

66+
class RNCSmartRefreshFactoryDelegate : public TurboModuleFactoryDelegate {
67+
public:
68+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
69+
if (name == "RNCSmartRefreshContext") {
70+
return std::make_shared<RNCSmartRefreshTurboModule>(ctx, name);
71+
}
72+
return nullptr;
73+
};
74+
};
75+
6576
class SmartRefreshLayoutPackage : public Package {
6677
public:
6778
SmartRefreshLayoutPackage(Package::Context ctx) : Package(ctx) {}
@@ -70,6 +81,10 @@ namespace rnoh {
7081
return std::make_shared<SmartRefreshLayoutPackageComponentInstanceFactoryDelegate>();
7182
}
7283

84+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
85+
return std::make_unique<RNCSmartRefreshFactoryDelegate>();
86+
}
87+
7388
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
7489
return {
7590
facebook::react::concreteComponentDescriptorProvider<
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
26+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
27+
import { SmartRefreshTurboModule } from './SmartRefreshTurboModule';
28+
29+
class SmartRefreshTurboModulesFactory extends TurboModulesFactory {
30+
createTurboModule(name: string): TurboModule | null {
31+
if (name === 'RNCSmartRefreshContext') {
32+
return new SmartRefreshTurboModule(this.ctx);
33+
}
34+
return null;
35+
}
36+
37+
hasTurboModule(name: string): boolean {
38+
return name === 'RNCSmartRefreshContext';
39+
}
40+
}
41+
42+
export class SmartRefreshPackage extends RNPackage {
43+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
44+
return new SmartRefreshTurboModulesFactory(ctx);
45+
}
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2024 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import { TurboModule } from "@rnoh/react-native-openharmony/ts";
26+
27+
export class SmartRefreshTurboModule extends TurboModule {
28+
cvp2px(value: number):{} {
29+
const v= vp2px(value);
30+
return {values:v};
31+
}
32+
}

harmony/smart_refresh_layout/ts.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
export * from "./src/main/ets/SmartRefreshTurboModule"
26+
export * from "./src/main/ets/SmartRefreshPackage"

0 commit comments

Comments
 (0)