Skip to content

Commit 286961f

Browse files
authored
Merge pull request #1 from react-native-oh-library/dev
add harmony support
2 parents 9004f93 + a955de9 commit 286961f

23 files changed

+841
-4
lines changed

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@react-native-oh-library:registry=https://npm.pkg.github.com
2+
//npm.pkg.github.com/:_authToken=${TOKEN}

harmony/geolocation.har

6.92 KB
Binary file not shown.

harmony/geolocation/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules
2+
/oh_modules
3+
/.preview
4+
/build
5+
/.cxx
6+
/.test
7+
oh-package-lock.json5
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"apiType": "stageMode",
3+
"targets": [
4+
{
5+
"name": "default",
6+
}
7+
]
8+
}

harmony/geolocation/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/geolocation/index.ets

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 ANT 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'

harmony/geolocation/oh-package.json5

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"license": "ISC",
3+
"types": "",
4+
"devDependencies": {
5+
"rnoh": "file:../rnoh"
6+
},
7+
"name": "geolocation",
8+
"description": "",
9+
"main": "index.ets",
10+
"version": "0.0.1",
11+
"dependencies": {}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
set(CMAKE_VERBOSE_MAKEFILE on)
3+
4+
file(GLOB rnoh_geolocation_SRC CONFIGURE_DEPENDS *.cpp)
5+
add_library(rnoh_geolocation SHARED ${rnoh_geolocation_SRC})
6+
target_include_directories(rnoh_geolocation PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7+
target_link_libraries(rnoh_geolocation PUBLIC rnoh)
8+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 ANT 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+
#ifndef GEO_LOCATION_PACKAGE_H
26+
#define GEO_LOCATION_PACKAGE_H
27+
28+
#include "RNOH/Package.h"
29+
#include "RNCGeolocationTurboModule.h"
30+
31+
using namespace rnoh;
32+
using namespace facebook;
33+
34+
class GeoLocationTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
35+
public:
36+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
37+
{
38+
if(name == "RNCGeolocation") {
39+
return std::make_shared<RNCGeolocationTurboModule>(ctx, name);
40+
}
41+
return nullptr;
42+
};
43+
};
44+
45+
namespace rnoh {
46+
class GeoLocationPackage : public Package {
47+
public:
48+
GeoLocationPackage(Package::Context ctx) : Package(ctx){}
49+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
50+
{
51+
return std::make_unique<GeoLocationTurboModuleFactoryDelegate>();
52+
}
53+
};
54+
} // namespace rnoh
55+
#endif
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 ANT 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 "RNCGeolocationTurboModule.h"
26+
27+
using namespace rnoh;
28+
using namespace facebook;
29+
30+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_setConfiguration(
31+
jsi::Runtime &rt,
32+
react::TurboModule & turboModule,
33+
const jsi::Value* args,
34+
size_t count) {
35+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setConfiguration", args, count));
36+
}
37+
38+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_requestAuthorization(
39+
jsi::Runtime &rt,
40+
react::TurboModule & turboModule,
41+
const jsi::Value* args,
42+
size_t count) {
43+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"requestAuthorization", args, count));
44+
}
45+
46+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_getCurrentPosition(
47+
jsi::Runtime &rt,
48+
react::TurboModule & turboModule,
49+
const jsi::Value* args,
50+
size_t count) {
51+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getCurrentPosition", args, count));
52+
}
53+
54+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_startObserving(
55+
jsi::Runtime &rt,
56+
react::TurboModule & turboModule,
57+
const jsi::Value* args,
58+
size_t count) {
59+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"startObserving", args, count));
60+
}
61+
62+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_stopObserving(
63+
jsi::Runtime &rt,
64+
react::TurboModule & turboModule,
65+
const jsi::Value* args,
66+
size_t count) {
67+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"stopObserving", args, count));
68+
}
69+
70+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_addListener(
71+
jsi::Runtime &rt,
72+
react::TurboModule & turboModule,
73+
const jsi::Value* args,
74+
size_t count) {
75+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"addListener", args, count));
76+
}
77+
78+
static jsi::Value __hostFunction_RNCGeolocationTurboModule_removeListeners(
79+
jsi::Runtime &rt,
80+
react::TurboModule & turboModule,
81+
const jsi::Value* args,
82+
size_t count) {
83+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"removeListeners", args, count));
84+
}
85+
86+
87+
88+
RNCGeolocationTurboModule::RNCGeolocationTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
89+
: ArkTSTurboModule(ctx,name)
90+
{
91+
methodMap_["setConfiguration"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_setConfiguration};
92+
methodMap_["requestAuthorization"]= MethodMetadata{2, __hostFunction_RNCGeolocationTurboModule_requestAuthorization};
93+
methodMap_["getCurrentPosition"]= MethodMetadata{3, __hostFunction_RNCGeolocationTurboModule_getCurrentPosition};
94+
methodMap_["startObserving"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_startObserving};
95+
methodMap_["stopObserving"]= MethodMetadata{0, __hostFunction_RNCGeolocationTurboModule_stopObserving};
96+
methodMap_["addListener"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_addListener};
97+
methodMap_["removeListeners"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_removeListeners};
98+
99+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 ANT 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+
#ifndef GEO_LOCATION_TURBOMODULE_H
26+
#define GEO_LOCATION_TURBOMODULE_H
27+
28+
#include <ReactCommon/TurboModule.h>
29+
#include "RNOH/ArkTSTurboModule.h"
30+
31+
namespace rnoh {
32+
class JSI_EXPORT RNCGeolocationTurboModule : public ArkTSTurboModule {
33+
public:
34+
RNCGeolocationTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
35+
};
36+
} // namespace rnoh
37+
38+
#endif
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 ANT 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 type Config = {
26+
skipPermissionRequests: boolean;
27+
authorizationLevel?: string;
28+
enableBackgroundLocationUpdates?: string;
29+
}
30+
31+
export type ReqLocOptions = {
32+
timeout?: number;
33+
maximumAge?: number;
34+
enableHighAccuracy?: boolean;
35+
}
36+
37+
export type GeolocationConfiguration = {
38+
skipPermissionRequests: boolean;
39+
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
40+
locationProvider?: 'playServices' | 'android' | 'auto';
41+
enableBackgroundLocationUpdates?: boolean;
42+
}
43+
44+
export type GeolocationOptions = {
45+
timeout?: number; //求位置 超时时间
46+
maximumAge?: number; //缓存位置多久
47+
enableHighAccuracy?: boolean; //gps or wifi
48+
distanceFilter?: number;
49+
useSignificantChanges?: boolean;
50+
interval?: number;
51+
fastestInterval?: number;
52+
}
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 ANT 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/ts';
26+
import type { TurboModule, TurboModuleContext } from 'rnoh/ts';
27+
import { RNCGeolocationTurboModule } from './RNCGeolocationTurboModule';
28+
29+
class GeoLocationTurboModulesFactory extends TurboModulesFactory {
30+
createTurboModule(name: string): TurboModule | null {
31+
if (name === 'RNCGeolocation') {
32+
return new RNCGeolocationTurboModule(this.ctx);
33+
}
34+
return null;
35+
}
36+
37+
hasTurboModule(name: string): boolean {
38+
return name === 'RNCGeolocation';
39+
}
40+
}
41+
42+
export class GeoLocationPackage extends RNPackage {
43+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
44+
return new GeoLocationTurboModulesFactory(ctx);
45+
}
46+
}

0 commit comments

Comments
 (0)