Skip to content

add harmony support #1

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 21, 2023
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
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react-native-oh-library:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${TOKEN}
Binary file added harmony/geolocation.har
Binary file not shown.
8 changes: 8 additions & 0 deletions harmony/geolocation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
oh-package-lock.json5

8 changes: 8 additions & 0 deletions harmony/geolocation/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"apiType": "stageMode",
"targets": [
{
"name": "default",
}
]
}
1 change: 1 addition & 0 deletions harmony/geolocation/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { harTasks } from '@ohos/hvigor-ohos-plugin';
25 changes: 25 additions & 0 deletions harmony/geolocation/index.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 ANT 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 './ts'
12 changes: 12 additions & 0 deletions harmony/geolocation/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"license": "ISC",
"types": "",
"devDependencies": {
"rnoh": "file:../rnoh"
},
"name": "geolocation",
"description": "",
"main": "index.ets",
"version": "0.0.1",
"dependencies": {}
}
8 changes: 8 additions & 0 deletions harmony/geolocation/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

file(GLOB rnoh_geolocation_SRC CONFIGURE_DEPENDS *.cpp)
add_library(rnoh_geolocation SHARED ${rnoh_geolocation_SRC})
target_include_directories(rnoh_geolocation PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(rnoh_geolocation PUBLIC rnoh)

55 changes: 55 additions & 0 deletions harmony/geolocation/src/main/cpp/GeoLocationPackage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* 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 ANT 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.
*/

#ifndef GEO_LOCATION_PACKAGE_H
#define GEO_LOCATION_PACKAGE_H

#include "RNOH/Package.h"
#include "RNCGeolocationTurboModule.h"

using namespace rnoh;
using namespace facebook;

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

namespace rnoh {
class GeoLocationPackage : public Package {
public:
GeoLocationPackage(Package::Context ctx) : Package(ctx){}
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
{
return std::make_unique<GeoLocationTurboModuleFactoryDelegate>();
}
};
} // namespace rnoh
#endif
99 changes: 99 additions & 0 deletions harmony/geolocation/src/main/cpp/RNCGeolocationTurboModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* 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 ANT 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 "RNCGeolocationTurboModule.h"

using namespace rnoh;
using namespace facebook;

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

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

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

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

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

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

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



RNCGeolocationTurboModule::RNCGeolocationTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
: ArkTSTurboModule(ctx,name)
{
methodMap_["setConfiguration"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_setConfiguration};
methodMap_["requestAuthorization"]= MethodMetadata{2, __hostFunction_RNCGeolocationTurboModule_requestAuthorization};
methodMap_["getCurrentPosition"]= MethodMetadata{3, __hostFunction_RNCGeolocationTurboModule_getCurrentPosition};
methodMap_["startObserving"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_startObserving};
methodMap_["stopObserving"]= MethodMetadata{0, __hostFunction_RNCGeolocationTurboModule_stopObserving};
methodMap_["addListener"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_addListener};
methodMap_["removeListeners"]= MethodMetadata{1, __hostFunction_RNCGeolocationTurboModule_removeListeners};

}
38 changes: 38 additions & 0 deletions harmony/geolocation/src/main/cpp/RNCGeolocationTurboModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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 ANT 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.
*/

#ifndef GEO_LOCATION_TURBOMODULE_H
#define GEO_LOCATION_TURBOMODULE_H

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

namespace rnoh {
class JSI_EXPORT RNCGeolocationTurboModule : public ArkTSTurboModule {
public:
RNCGeolocationTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
};
} // namespace rnoh

#endif
52 changes: 52 additions & 0 deletions harmony/geolocation/src/main/ets/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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 ANT 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 type Config = {
skipPermissionRequests: boolean;
authorizationLevel?: string;
enableBackgroundLocationUpdates?: string;
}

export type ReqLocOptions = {
timeout?: number;
maximumAge?: number;
enableHighAccuracy?: boolean;
}

export type GeolocationConfiguration = {
skipPermissionRequests: boolean;
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
locationProvider?: 'playServices' | 'android' | 'auto';
enableBackgroundLocationUpdates?: boolean;
}

export type GeolocationOptions = {
timeout?: number; //求位置 超时时间
maximumAge?: number; //缓存位置多久
enableHighAccuracy?: boolean; //gps or wifi
distanceFilter?: number;
useSignificantChanges?: boolean;
interval?: number;
fastestInterval?: number;
}
46 changes: 46 additions & 0 deletions harmony/geolocation/src/main/ets/GeoLocationPackage.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 ANT 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/ts';
import type { TurboModule, TurboModuleContext } from 'rnoh/ts';
import { RNCGeolocationTurboModule } from './RNCGeolocationTurboModule';

class GeoLocationTurboModulesFactory extends TurboModulesFactory {
createTurboModule(name: string): TurboModule | null {
if (name === 'RNCGeolocation') {
return new RNCGeolocationTurboModule(this.ctx);
}
return null;
}

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

export class GeoLocationPackage extends RNPackage {
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
return new GeoLocationTurboModulesFactory(ctx);
}
}
Loading