Skip to content

Commit 9ed09e3

Browse files
committed
支持鸿蒙平台
Signed-off-by: Mrliwang <965027894@qq.com>
1 parent 7a04979 commit 9ed09e3

28 files changed

+687
-3
lines changed

harmony/view_overflow.har

6.58 KB
Binary file not shown.

harmony/view_overflow/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
/.preview
3+
/build
4+
/.cxx
5+
/oh_modules
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default class BuildProfile {
2+
static readonly HAR_VERSION = '0.0.5-0.0.1';
3+
static readonly BUILD_MODE_NAME = 'debug';
4+
static readonly DEBUG = true;
5+
static readonly TARGET_NAME = 'default';
6+
}

harmony/view_overflow/Index.ets

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
export * from './ts'
26+
export * from './src/main/ets/RNViewOverflow'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"apiType": "stageMode",
3+
"targets": [
4+
{
5+
"name": "default",
6+
"runtimeOS": "HarmonyOS"
7+
}
8+
]
9+
}

harmony/view_overflow/hvigorfile.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2+
export { harTasks } from '@ohos/hvigor-ohos-plugin';
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
license: 'ISC',
3+
types: '',
4+
name: '@react-native-oh-tpl/react-native-view_overflow',
5+
version: '0.0.5-0.0.1',
6+
description: '',
7+
main: 'Index.ets',
8+
type: 'module',
9+
dependencies: {
10+
"@rnoh/react-native-openharmony": 'file:../react_native_openharmony'
11+
},
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
set(CMAKE_VERBOSE_MAKEFILE on)
3+
4+
file(GLOB rnoh_view_overflow_SRC CONFIGURE_DEPENDS *.cpp)
5+
add_library(rnoh_view_overflow SHARED ${rnoh_view_overflow_SRC})
6+
target_include_directories(rnoh_view_overflow PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7+
target_link_libraries(rnoh_view_overflow PUBLIC rnoh)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// NOTE: This entire file should be codegen'ed.
2+
3+
#include "OverflowTurboModuleSpec.h"
4+
5+
using namespace rnoh;
6+
using namespace facebook;
7+
8+
NativeOverflowTurboModuleSpecJSI::NativeOverflowTurboModuleSpecJSI(
9+
const ArkTSTurboModule::Context ctx,
10+
const std::string name)
11+
: ArkTSTurboModule(ctx, name) {
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// NOTE: This entire file should be codegen'ed.
2+
#pragma once
3+
4+
#include <ReactCommon/TurboModule.h>
5+
#include "RNOH/ArkTSTurboModule.h"
6+
7+
namespace rnoh {
8+
9+
class JSI_EXPORT NativeOverflowTurboModuleSpecJSI : public ArkTSTurboModule {
10+
public:
11+
NativeOverflowTurboModuleSpecJSI(
12+
const ArkTSTurboModule::Context ctx,
13+
const std::string name);
14+
};
15+
16+
} // namespace rnoh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "RNOverflowPackage.h"
2+
#include "RNOH/RNInstanceCAPI.h"
3+
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
4+
#include "RNOHCorePackage/ComponentBinders/ViewComponentNapiBinder.h"
5+
#include "OverflowTurboModuleSpec.h"
6+
#include "RNViewOverflowComponentDescriptor.h"
7+
#include "RNViewOverflowComponentInstance.h"
8+
9+
using namespace rnoh;
10+
using namespace facebook;
11+
12+
class RNViewOverflowJSIBinder : public ViewComponentJSIBinder {
13+
14+
};
15+
16+
class OverflowTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
17+
public:
18+
SharedTurboModule createTurboModule(Context ctx, const std::string& name)
19+
const override {
20+
if (name == "OverflowTurboModule") {
21+
return std::make_shared<NativeOverflowTurboModuleSpecJSI>(ctx, name);
22+
}
23+
return nullptr;
24+
};
25+
};
26+
27+
std::unique_ptr<TurboModuleFactoryDelegate>RNOverflowPackage::createTurboModuleFactoryDelegate() {
28+
return std::make_unique<OverflowTurboModuleFactoryDelegate>();
29+
}
30+
31+
std::vector<react::ComponentDescriptorProvider>RNOverflowPackage::createComponentDescriptorProviders() {
32+
return {
33+
react::concreteComponentDescriptorProvider<react::RNViewOverflowComponentDescriptor>(),
34+
};
35+
}
36+
37+
ComponentJSIBinderByString RNOverflowPackage::createComponentJSIBinderByName() {
38+
return {
39+
{"RNViewOverflow", std::make_shared<RNViewOverflowJSIBinder>()},
40+
};
41+
}
42+
43+
class OverflowArkTSMessageHandler : public ArkTSMessageHandler {
44+
void handleArkTSMessage(const Context& ctx) override {
45+
auto rnInstance = ctx.rnInstance.lock();
46+
if (rnInstance) {
47+
if (ctx.messageName == "Overflow_MESSAGE") {
48+
rnInstance->postMessageToArkTS(ctx.messageName, ctx.messagePayload);
49+
} else if (ctx.messageName == "BLOCK_NATIVE_RESPONDER") {
50+
auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
51+
auto maybeTag = rnInstanceCAPI->findComponentInstanceTagById(ctx.messagePayload["componentInstanceId"].asString());
52+
if (maybeTag.has_value()) {
53+
auto componentInstance = rnInstanceCAPI->findComponentInstanceByTag(maybeTag.value());
54+
componentInstance->setNativeResponderBlocked(ctx.messagePayload["isBlocked"].asBool(), ctx.messagePayload["origin"].asString());
55+
}
56+
}
57+
}
58+
};
59+
};
60+
61+
std::vector<ArkTSMessageHandler::Shared>
62+
RNOverflowPackage::createArkTSMessageHandlers() {
63+
return {std::make_shared<OverflowArkTSMessageHandler>()};
64+
}
65+
66+
ComponentInstanceFactoryDelegate::Shared
67+
rnoh::RNOverflowPackage::createComponentInstanceFactoryDelegate() {
68+
class OverflowComponentInstanceFactoryDelegate
69+
: public ComponentInstanceFactoryDelegate {
70+
public:
71+
ComponentInstance::Shared create(ComponentInstance::Context ctx) override {
72+
DLOG(INFO) << "liwang----c++--->OverflowPackage create:" << ctx.componentName;
73+
if (ctx.componentName == "RNViewOverflow") {
74+
return std::make_shared<RNViewOverflowComponentInstance>(ctx);
75+
}
76+
return nullptr;
77+
}
78+
};
79+
return std::make_shared<OverflowComponentInstanceFactoryDelegate>();
80+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "RNOH/Package.h"
2+
3+
namespace rnoh {
4+
5+
class RNOverflowPackage : public Package {
6+
public:
7+
RNOverflowPackage(Package::Context ctx) : Package(ctx) {}
8+
9+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override;
10+
11+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override;
12+
13+
ComponentJSIBinderByString createComponentJSIBinderByName() override;
14+
15+
std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
16+
17+
ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override;
18+
};
19+
} // namespace rnoh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
4+
#include <react/renderer/components/view/ViewShadowNode.h>
5+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
6+
#include <react/renderer/core/propsConversions.h>
7+
8+
namespace facebook {
9+
namespace react {
10+
11+
inline const char RNViewOverflowComponentName[] = "RNViewOverflow";
12+
13+
class RNViewOverflowProps : public ViewProps {
14+
public:
15+
RNViewOverflowProps() = default;
16+
17+
RNViewOverflowProps(
18+
const PropsParserContext& context,
19+
const RNViewOverflowProps& sourceProps,
20+
const RawProps& rawProps)
21+
: ViewProps(context, sourceProps, rawProps) {}
22+
};
23+
24+
class RNViewOverflowEventEmitter : public ViewEventEmitter {
25+
public:
26+
using ViewEventEmitter::ViewEventEmitter;
27+
};
28+
29+
using RNViewOverflowShadowNode = ConcreteViewShadowNode<RNViewOverflowComponentName, RNViewOverflowProps, RNViewOverflowEventEmitter>;
30+
31+
class RNViewOverflowComponentDescriptor final
32+
: public ConcreteComponentDescriptor<RNViewOverflowShadowNode> {
33+
public:
34+
RNViewOverflowComponentDescriptor(ComponentDescriptorParameters const& parameters)
35+
: ConcreteComponentDescriptor(parameters) {}
36+
};
37+
38+
} // namespace react
39+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "RNViewOverflowComponentInstance.h"
2+
3+
namespace rnoh {
4+
5+
RNViewOverflowComponentInstance::RNViewOverflowComponentInstance(Context context)
6+
: CppComponentInstance(std::move(context)) {
7+
m_stackNode.setClip(true);
8+
}
9+
10+
void RNViewOverflowComponentInstance::onChildInserted(ComponentInstance::Shared const& childComponentInstance, std::size_t index) {
11+
CppComponentInstance::onChildInserted(childComponentInstance, index);
12+
m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index + 1);
13+
}
14+
15+
void RNViewOverflowComponentInstance::onChildRemoved(ComponentInstance::Shared const& childComponentInstance) {
16+
CppComponentInstance::onChildRemoved(childComponentInstance);
17+
m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
18+
}
19+
20+
void RNViewOverflowComponentInstance::onPropsChanged(SharedConcreteProps const& props) {
21+
CppComponentInstance::onPropsChanged(props);
22+
}
23+
24+
void RNViewOverflowComponentInstance::handleCommand(std::string const& commandName, folly::dynamic const& args) {
25+
CppComponentInstance::handleCommand(commandName, args);
26+
}
27+
28+
ArkUINode& RNViewOverflowComponentInstance::getLocalRootArkUINode() {
29+
return m_stackNode;
30+
}
31+
32+
} // namespace rnoh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "RNOH/CppComponentInstance.h"
4+
#include "RNOH/arkui/StackNode.h"
5+
#include "RNOH/arkui/TextNode.h"
6+
#include "RNViewOverflowComponentDescriptor.h"
7+
8+
namespace rnoh {
9+
class RNViewOverflowComponentInstance
10+
: public CppComponentInstance<facebook::react::RNViewOverflowShadowNode>
11+
{
12+
private:
13+
StackNode m_stackNode{};
14+
15+
public:
16+
RNViewOverflowComponentInstance(Context context);
17+
18+
void onChildInserted(ComponentInstance::Shared const& childComponentInstance, std::size_t index) override;
19+
void onChildRemoved(ComponentInstance::Shared const& childComponentInstance) override;
20+
void onPropsChanged(SharedConcreteProps const& props) override;
21+
void handleCommand(std::string const& commandName, folly::dynamic const& args) override;
22+
ArkUINode& getLocalRootArkUINode() override;
23+
};
24+
} // namespace rnoh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 hilog from '@ohos.hilog';
26+
27+
class Logger {
28+
private domain : number;
29+
private prefix : string;
30+
private format : string = '%{public}s, %{public}s';
31+
private isDebug : boolean;
32+
33+
/**
34+
* constructor.
35+
*
36+
* @param Prefix Identifies the log tag.
37+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
38+
*/
39+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
40+
this.prefix = prefix;
41+
this.domain = domain;
42+
this.isDebug = isDebug;
43+
}
44+
45+
debug(...args: string[]): void {
46+
if (this.isDebug) {
47+
hilog.debug(this.domain, this.prefix, this.format, args);
48+
}
49+
}
50+
51+
info(...args: string[]): void {
52+
hilog.info(this.domain, this.prefix, this.format, args);
53+
}
54+
55+
warn(...args: string[]) : void {
56+
hilog.warn(this.domain, this.prefix, this.format, args);
57+
}
58+
59+
error(...args: string[]) : void {
60+
hilog.error(this.domain, this.prefix, this.format, args);
61+
}
62+
}
63+
64+
export default new Logger('RNViewOverflow', 0xFF00, false)

0 commit comments

Comments
 (0)