Skip to content

Commit a98cfb7

Browse files
committed
fs鸿蒙化;
1 parent 64aa755 commit a98cfb7

35 files changed

+777
-3
lines changed

FS.common.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*/
55

66
'use strict';
7+
import { TurboModuleRegistry } from "react-native";
78

89
// This file supports both iOS and Android
910

10-
var RNFSManager = require('react-native').NativeModules.RNFSManager;
11+
var RNFSManager = TurboModuleRegistry?TurboModuleRegistry.get('ReactNativeFs'):NativeModules.RNFSManager;
1112

1213
var NativeEventEmitter = require('react-native').NativeEventEmitter;
1314

@@ -638,7 +639,7 @@ var RNFS = {
638639
MainBundlePath: RNFSManager.RNFSMainBundlePath,
639640
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
640641
ExternalCachesDirectoryPath: RNFSManager.RNFSExternalCachesDirectoryPath,
641-
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
642+
DocumentDirectoryPath: (isIOS || isWindows )? RNFSManager.RNFSDocumentDirectoryPath:RNFSManager.getConstants().FileSandBoxPath,
642643
DownloadDirectoryPath: RNFSManager.RNFSDownloadDirectoryPath,
643644
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
644645
ExternalStorageDirectoryPath: RNFSManager.RNFSExternalStorageDirectoryPath,
@@ -647,6 +648,7 @@ var RNFS = {
647648
PicturesDirectoryPath: RNFSManager.RNFSPicturesDirectoryPath, // For Windows
648649
FileProtectionKeys: RNFSManager.RNFSFileProtectionKeys,
649650
RoamingDirectoryPath: RNFSManager.RNFSRoamingDirectoryPath, // For Windows
651+
//FileSandBoxPath: RNFSManager.getConstants().FileSandBoxPath, // For harmony
650652
};
651653

652654
module.exports = RNFS;

harmony/fs.har

13 KB
Binary file not shown.

harmony/fs/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
/oh_modules
3+
/.preview
4+
/build
5+
/.cxx
6+
/.test

harmony/fs/BuildProfile.ets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default class BuildProfile {
2+
static readonly BUNDLE_NAME = 'com.rnoh.tester';
3+
static readonly VERSION_CODE = 1000000;
4+
static readonly VERSION_NAME = '1.0.0';
5+
static readonly HAR_VERSION = '1.0.0';
6+
static readonly BUILD_MODE_NAME = 'Debug';
7+
static readonly DEBUG = true;
8+
}

harmony/fs/build-profile.json5

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"apiType": "stageMode",
3+
4+
"targets": [
5+
{
6+
"name": "default"
7+
},
8+
{
9+
"name": "ohosTest",
10+
}
11+
]
12+
}

harmony/fs/hvigorfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { harTasks } from '@ohos/hvigor-ohos-plugin';

harmony/fs/index.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ts'

harmony/fs/oh-package.json5

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "fs",
3+
"version": "1.0.0",
4+
"description": "Please describe the basic information.",
5+
"main": "index.ets",
6+
"types": "module",
7+
"dependencies": {
8+
"rnoh": "file:../rnoh"
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
file(GLOB rnoh_fs_SRC CONFIGURE_DEPENDS *.cpp)
10+
add_library(rnoh_fs SHARED ${rnoh_fs_SRC})
11+
target_include_directories(rnoh_fs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
12+
target_link_libraries(rnoh_fs PUBLIC rnoh)

harmony/fs/src/main/cpp/FsPackage.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "RNOH/Package.h"
2+
#include "FsTurboModule.h"
3+
4+
using namespace rnoh;
5+
using namespace facebook;
6+
7+
class NativeRTNFsFactoryDelegate : public TurboModuleFactoryDelegate {
8+
public:
9+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
10+
if (name == "ReactNativeFs") {
11+
return std::make_shared<FsTurboModule>(ctx, name);
12+
}
13+
return nullptr;
14+
}
15+
};
16+
17+
namespace rnoh {
18+
19+
class FsPackage : public Package {
20+
public:
21+
FsPackage(Package::Context ctx) : Package(ctx) {}
22+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
23+
return std::make_unique<NativeRTNFsFactoryDelegate>();
24+
}
25+
};
26+
} // namespace rnoh
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Do not edit this file as changes may cause incorrect behavior and will be lost
6+
* once the code is regenerated.
7+
*
8+
* @generated by codegen project: GenerateModuleJniCpp.js
9+
*/
10+
11+
#include "FsTurboModule.h"
12+
#include "RNOH/ArkTSTurboModule.h"
13+
14+
using namespace rnoh;
15+
using namespace facebook;
16+
17+
static jsi::Value __hostFunction_FsTurboModule_getConstants(jsi::Runtime &rt, react::TurboModule &turboModule,
18+
const jsi::Value *args, size_t count) {
19+
{
20+
return jsi::Value(static_cast<ArkTSTurboModule &>(turboModule).call(rt, "getConstants", args, count));
21+
}
22+
}
23+
24+
static jsi::Value __hostFunction_FsTurboModule_appendFile(jsi::Runtime &rt,
25+
react::TurboModule &turboModule,
26+
const jsi::Value *args, size_t count) {
27+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt,"appendFile",args, count);
28+
}
29+
30+
static jsi::Value __hostFunction_FsTurboModule_copyFile(jsi::Runtime &rt,
31+
react::TurboModule &turboModule,
32+
const jsi::Value *args, size_t count) {
33+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "copyFile",args, count);
34+
}
35+
36+
static jsi::Value __hostFunction_FsTurboModule_exists(jsi::Runtime &rt, react::TurboModule &turboModule,
37+
const jsi::Value *args, size_t count) {
38+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "exists",args,count);
39+
}
40+
41+
static jsi::Value __hostFunction_FsTurboModule_mkdir(jsi::Runtime &rt, react::TurboModule &turboModule,
42+
const jsi::Value *args, size_t count) {
43+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "mkdir", args,count);
44+
}
45+
46+
47+
static jsi::Value __hostFunction_FsTurboModule_readFile(jsi::Runtime &rt,
48+
react::TurboModule &turboModule,
49+
const jsi::Value *args, size_t count) {
50+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "readFile",args, count);
51+
}
52+
53+
54+
static jsi::Value __hostFunction_FsTurboModule_writeFile(jsi::Runtime &rt,
55+
react::TurboModule &turboModule,
56+
const jsi::Value *args, size_t count) {
57+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "writeFile",args, count);
58+
}
59+
60+
61+
static jsi::Value __hostFunction_FsTurboModule_readFileAssets(jsi::Runtime &rt,
62+
react::TurboModule &turboModule,
63+
const jsi::Value *args,
64+
size_t count) {
65+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "readFileAssets", args, count);
66+
}
67+
68+
static jsi::Value __hostFunction_NativeFsSpecJSI_unlink(jsi::Runtime &rt, react::TurboModule &turboModule,
69+
const jsi::Value *args, size_t count) {
70+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "unlink", args, count);
71+
}
72+
73+
FsTurboModule::FsTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
74+
: ArkTSTurboModule(ctx, name) {
75+
methodMap_["getConstants"] = MethodMetadata{0, __hostFunction_FsTurboModule_getConstants};
76+
methodMap_["readFile"] = MethodMetadata{1, __hostFunction_FsTurboModule_readFile};
77+
methodMap_["exists"] = MethodMetadata{1, __hostFunction_FsTurboModule_exists};
78+
methodMap_["mkdir"] = MethodMetadata{2, __hostFunction_FsTurboModule_mkdir};
79+
methodMap_["appendFile"] = MethodMetadata{2, __hostFunction_FsTurboModule_appendFile};
80+
methodMap_["writeFile"] = MethodMetadata{2, __hostFunction_FsTurboModule_writeFile};
81+
methodMap_["readFileAssets"] = MethodMetadata{1, __hostFunction_FsTurboModule_readFileAssets};
82+
methodMap_["copyFile"] = MethodMetadata{2, __hostFunction_FsTurboModule_copyFile};
83+
methodMap_["unlink"] = MethodMetadata{1, __hostFunction_NativeFsSpecJSI_unlink};
84+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// NOTE: This entire file should be codegen'ed.
2+
#pragma once
3+
#include "RNOH/ArkTSTurboModule.h"
4+
5+
namespace rnoh {
6+
7+
class JSI_EXPORT FsTurboModule : public ArkTSTurboModule {
8+
public:
9+
FsTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
10+
};
11+
12+
} // namespace rnoh

harmony/fs/src/main/ets/FsPackage.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RNPackage, TurboModulesFactory } from 'rnoh/ts';
2+
import type { TurboModule, TurboModuleContext } from 'rnoh/ts';
3+
import { FsTurboModule } from './FsTurboModule';
4+
5+
class FsTurboModulesFactory extends TurboModulesFactory {
6+
createTurboModule(name: string): TurboModule | null {
7+
if (name === 'ReactNativeFs') {
8+
// 上下文对象
9+
globalThis.uiAbilityContext = this.ctx.uiAbilityContext;
10+
return new FsTurboModule(this.ctx);
11+
}
12+
return null;
13+
}
14+
15+
hasTurboModule(name: string): boolean {
16+
return name === 'ReactNativeFs';
17+
}
18+
}
19+
20+
export class FsPackage extends RNPackage {
21+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
22+
return new FsTurboModulesFactory(ctx);
23+
}
24+
}

0 commit comments

Comments
 (0)