Skip to content

fix:solve question setSize method does not work causing a blank header #22

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion harmony/smart_refresh_layout/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
*/
export * from "./src/main/ets/SmartRefreshControl"
export * from "./src/main/ets/RNCAnyHeader"
export * from "./src/main/ets/RNCDefaultHeader"
export * from "./src/main/ets/RNCDefaultHeader"
export * from './ts'
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ namespace rnoh {

void RNCAnyHeaderComponentInstance::finalizeUpdates() {
std::vector<ComponentInstance::Shared> child = getChildren();
float childHeight = 0.0;
for (ComponentInstance::Shared c : child) {
if (c) {
auto height = c->getLayoutMetrics().frame.size.height;
if (height>childHeight) {
childHeight = height;
}
}
}
m_stackNode.setSize(facebook::react::Size({ getLayoutMetrics().frame.size.width, childHeight}));
float childHeight = 0.0;
for (ComponentInstance::Shared c : child) {
if (c) {
auto height = c->getLayoutMetrics().frame.size.height;
if (height>childHeight) {
childHeight = height;
}
}
}
auto rnInstancePtr = this->m_deps->rnInstance.lock();
if (rnInstancePtr != nullptr) {
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});;
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {childHeight});
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
}
}

} // namespace rnoh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#pragma once

#include <ReactCommon/TurboModule.h>
#include "RNOH/ArkTSTurboModule.h"

namespace rnoh {

class JSI_EXPORT RNCSmartRefreshTurboModule : public ArkTSTurboModule {
public:
RNCSmartRefreshTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
};

} // namespace rnoh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "RNCSmartRefreshTurbomodule.h"

using namespace rnoh;
using namespace facebook;

static jsi::Value __hostFunction_RNCSmartRefreshTurboModule_cvp2px(jsi::Runtime &rt,
react::TurboModule &turboModule,
const jsi::Value *args, size_t count)
{
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "cvp2px", args, count);
}

RNCSmartRefreshTurboModule::RNCSmartRefreshTurboModule(const ArkTSTurboModule::Context ctx,
const std::string name)
: ArkTSTurboModule(ctx, name)
{
methodMap_["cvp2px"] = MethodMetadata{0, __hostFunction_RNCSmartRefreshTurboModule_cvp2px};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "RNCDefaultHeaderComponentInstance.h"
#include "RNCClassicsHeaderComponentInstance.h"
#include "RNCMaterialHeaderComponentInstance.h"
#include "RNCSmartRefreshTurboModule.h"

namespace rnoh {

Expand Down Expand Up @@ -62,6 +63,16 @@ namespace rnoh {
}
};

class RNCSmartRefreshFactoryDelegate : public TurboModuleFactoryDelegate {
public:
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
if (name == "RNCSmartRefreshContext") {
return std::make_shared<RNCSmartRefreshTurboModule>(ctx, name);
}
return nullptr;
};
};

class SmartRefreshLayoutPackage : public Package {
public:
SmartRefreshLayoutPackage(Package::Context ctx) : Package(ctx) {}
Expand All @@ -70,6 +81,10 @@ namespace rnoh {
return std::make_shared<SmartRefreshLayoutPackageComponentInstanceFactoryDelegate>();
}

std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
return std::make_unique<RNCSmartRefreshFactoryDelegate>();
}

std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
return {
facebook::react::concreteComponentDescriptorProvider<
Expand Down
46 changes: 46 additions & 0 deletions harmony/smart_refresh_layout/src/main/ets/SmartRefreshPackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

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

class SmartRefreshTurboModulesFactory extends TurboModulesFactory {
createTurboModule(name: string): TurboModule | null {
if (name === 'RNCSmartRefreshContext') {
return new SmartRefreshTurboModule(this.ctx);
}
return null;
}

hasTurboModule(name: string): boolean {
return name === 'RNCSmartRefreshContext';
}
}

export class SmartRefreshPackage extends RNPackage {
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
return new SmartRefreshTurboModulesFactory(ctx);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* MIT License
*
* Copyright (C) 2024 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import { TurboModule } from "@rnoh/react-native-openharmony/ts";

export class SmartRefreshTurboModule extends TurboModule {
cvp2px(value: number):{} {
const v= vp2px(value);
return {values:v};
}
}
26 changes: 26 additions & 0 deletions harmony/smart_refresh_layout/ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

export * from "./src/main/ets/SmartRefreshTurboModule"
export * from "./src/main/ets/SmartRefreshPackage"