@react-native-ohos/react-native-haptic-feedback 2.3.4-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/RNReactNativeHapticFeedback.podspec +29 -0
- package/harmony/haptic_feedback/BuildProfile.ets +17 -0
- package/harmony/haptic_feedback/build-profile.json5 +28 -0
- package/harmony/haptic_feedback/hvigorfile.ts +6 -0
- package/harmony/haptic_feedback/index.ets +25 -0
- package/harmony/haptic_feedback/obfuscation-rules.txt +18 -0
- package/harmony/haptic_feedback/oh-package.json5 +12 -0
- package/harmony/haptic_feedback/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/haptic_feedback/src/main/cpp/RNHapticFeedback.cpp +21 -0
- package/harmony/haptic_feedback/src/main/cpp/RNHapticFeedback.h +21 -0
- package/harmony/haptic_feedback/src/main/cpp/RNHapticFeedbackPackage.h +37 -0
- package/harmony/haptic_feedback/src/main/ets/Logger.ts +46 -0
- package/harmony/haptic_feedback/src/main/ets/RNHapticFeedbackPackage.ts +29 -0
- package/harmony/haptic_feedback/src/main/ets/RNHapticFeedbackTurboModule.ts +151 -0
- package/harmony/haptic_feedback/src/main/ets/generated/components/ts.ts +8 -0
- package/harmony/haptic_feedback/src/main/ets/generated/index.ets +8 -0
- package/harmony/haptic_feedback/src/main/ets/generated/ts.ts +9 -0
- package/harmony/haptic_feedback/src/main/ets/generated/turboModules/RNHapticFeedback.ts +16 -0
- package/harmony/haptic_feedback/src/main/ets/generated/turboModules/ts.ts +8 -0
- package/harmony/haptic_feedback/src/main/module.json5 +12 -0
- package/harmony/haptic_feedback/src/main/resources/base/element/color.json +8 -0
- package/harmony/haptic_feedback/src/main/resources/base/element/string.json +16 -0
- package/harmony/haptic_feedback/src/main/resources/base/media/background.png +0 -0
- package/harmony/haptic_feedback/src/main/resources/base/media/foreground.png +0 -0
- package/harmony/haptic_feedback/src/main/resources/base/media/layered_image.json +7 -0
- package/harmony/haptic_feedback/src/main/resources/base/media/startIcon.png +0 -0
- package/harmony/haptic_feedback/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/haptic_feedback/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/effectClick.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/effectDoubleClick.json +38 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/effectHeavyClick.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/effectTick.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/impactHeavy.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/impactLight.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/impactMedium.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/notificationError.json +58 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/notificationSuccess.json +38 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/notificationWarning.json +38 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/rigid.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/selection.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/rawfile/soft.json +28 -0
- package/harmony/haptic_feedback/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/haptic_feedback/ts.ts +26 -0
- package/harmony/haptic_feedback.har +0 -0
- package/lib/commonjs/codegenSpec/NativeHapticFeedback.js +9 -0
- package/lib/commonjs/codegenSpec/NativeHapticFeedback.js.map +1 -0
- package/lib/commonjs/index.js +49 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +32 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/codegenSpec/NativeHapticFeedback.js +5 -0
- package/lib/module/codegenSpec/NativeHapticFeedback.js.map +1 -0
- package/lib/module/index.js +30 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +28 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/codegenSpec/NativeHapticFeedback.d.ts +10 -0
- package/lib/typescript/codegenSpec/NativeHapticFeedback.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +29 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +117 -0
- package/src/codegenSpec/NativeHapticFeedback.ts +14 -0
- package/src/index.ts +31 -0
- package/src/types.ts +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Michael Kuczera
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"Name": "react-native-haptic-feedback",
|
|
4
|
+
"License": "MIT License",
|
|
5
|
+
"License File": "https://github.com/mkuczera/react-native-haptic-feedback/blob/master/LICENSE",
|
|
6
|
+
"Version Number": "2.3.3",
|
|
7
|
+
"Owner" : "xiafeng@huawei.com",
|
|
8
|
+
"Upstream URL": "https://github.com/mkuczera/react-native-haptic-feedback",
|
|
9
|
+
"Description": "React-Native Haptic Feedback for iOS with Android similar behaviour."
|
|
10
|
+
}
|
|
11
|
+
]
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @react-native-ohos/react-native-haptic-feedback
|
|
2
|
+
|
|
3
|
+
This project is based on [react-native-haptic-feedback@2.3.3](https://github.com/mkuczera/react-native-haptic-feedback/tree/v2.3.3)
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
- [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-haptic-feedback.md)
|
|
8
|
+
|
|
9
|
+
- [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-haptic-feedback.md)
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
This library is licensed under [The MIT License (MIT)](https://github.com/mkuczera/react-native-haptic-feedback/blob/master/LICENSE)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
package = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'package.json')))
|
|
3
|
+
|
|
4
|
+
Pod::Spec.new do |s|
|
|
5
|
+
s.name = "RNReactNativeHapticFeedback"
|
|
6
|
+
s.version = package["version"]
|
|
7
|
+
s.summary = package["description"]
|
|
8
|
+
s.description = <<-DESC
|
|
9
|
+
react-native-haptic-feedback
|
|
10
|
+
DESC
|
|
11
|
+
s.homepage = "https://github.com/mkuczera/react-native-haptic-feedback"
|
|
12
|
+
s.license = "MIT"
|
|
13
|
+
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
|
|
14
|
+
s.author = { "author" => "m.kuczera@gmail.com" }
|
|
15
|
+
s.platform = :ios, "12.4"
|
|
16
|
+
s.source = { :git => "https://github.com/mkuczera/react-native-haptic-feedback.git", :tag => "v#{s.version.to_s}" }
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
18
|
+
s.requires_arc = true
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# This guard prevent to install the dependencies when we run `pod install` in the old architecture.
|
|
22
|
+
if defined?(install_modules_dependencies()) != nil
|
|
23
|
+
install_modules_dependencies(s)
|
|
24
|
+
else
|
|
25
|
+
s.dependency 'React-Core'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
|
+
*/
|
|
4
|
+
export const HAR_VERSION = '2.3.4-rc.1';
|
|
5
|
+
export const BUILD_MODE_NAME = 'debug';
|
|
6
|
+
export const DEBUG = true;
|
|
7
|
+
export const TARGET_NAME = 'default';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* BuildProfile Class is used only for compatibility purposes.
|
|
11
|
+
*/
|
|
12
|
+
export default class BuildProfile {
|
|
13
|
+
static readonly HAR_VERSION = HAR_VERSION;
|
|
14
|
+
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
|
|
15
|
+
static readonly DEBUG = DEBUG;
|
|
16
|
+
static readonly TARGET_NAME = TARGET_NAME;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiType": "stageMode",
|
|
3
|
+
"buildOption": {
|
|
4
|
+
},
|
|
5
|
+
"buildOptionSet": [
|
|
6
|
+
{
|
|
7
|
+
"name": "release",
|
|
8
|
+
"arkOptions": {
|
|
9
|
+
"obfuscation": {
|
|
10
|
+
"ruleOptions": {
|
|
11
|
+
"enable": true,
|
|
12
|
+
"files": [
|
|
13
|
+
"./obfuscation-rules.txt"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
"targets": [
|
|
21
|
+
{
|
|
22
|
+
"name": "default"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "ohosTest",
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2025 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";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Define project specific obfuscation rules here.
|
|
2
|
+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
|
3
|
+
#
|
|
4
|
+
# For more details, see
|
|
5
|
+
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
|
|
6
|
+
|
|
7
|
+
# Obfuscation options:
|
|
8
|
+
# -disable-obfuscation: disable all obfuscations
|
|
9
|
+
# -enable-property-obfuscation: obfuscate the property names
|
|
10
|
+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
|
11
|
+
# -compact: remove unnecessary blank spaces and all line feeds
|
|
12
|
+
# -remove-log: remove all console.* statements
|
|
13
|
+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
|
14
|
+
# -apply-namecache: reuse the given cache file
|
|
15
|
+
|
|
16
|
+
# Keep options:
|
|
17
|
+
# -keep-property-name: specifies property names that you want to keep
|
|
18
|
+
# -keep-global-name: specifies names that you want to keep in the global scope
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/react-native-haptic-feedback",
|
|
3
|
+
"version": "2.3.4-rc.1",
|
|
4
|
+
"description": "Please describe the basic information.",
|
|
5
|
+
"main": "index.ets",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@rnoh/react-native-openharmony": 'file:../../node_modules/react-native-harmony/harmony/react_native_openharmony.har'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
3
|
+
|
|
4
|
+
file(GLOB rnoh_haptic_feedback_SRC CONFIGURE_DEPENDS *.cpp)
|
|
5
|
+
add_library(rnoh_haptic_feedback SHARED ${rnoh_haptic_feedback_SRC})
|
|
6
|
+
target_include_directories(rnoh_haptic_feedback PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
7
|
+
target_link_libraries(rnoh_haptic_feedback PUBLIC rnoh)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "RNHapticFeedback.h"
|
|
11
|
+
|
|
12
|
+
namespace rnoh {
|
|
13
|
+
using namespace facebook;
|
|
14
|
+
|
|
15
|
+
RNHapticFeedback::RNHapticFeedback(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
16
|
+
methodMap_ = {
|
|
17
|
+
ARK_METHOD_METADATA(trigger, 2),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
13
|
+
|
|
14
|
+
namespace rnoh {
|
|
15
|
+
|
|
16
|
+
class JSI_EXPORT RNHapticFeedback : public ArkTSTurboModule {
|
|
17
|
+
public:
|
|
18
|
+
RNHapticFeedback(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "RNOH/Package.h"
|
|
13
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
14
|
+
#include "RNHapticFeedback.h"
|
|
15
|
+
|
|
16
|
+
namespace rnoh {
|
|
17
|
+
|
|
18
|
+
class RNHapticFeedbackPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
19
|
+
public:
|
|
20
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
21
|
+
if (name == "RNHapticFeedback") {
|
|
22
|
+
return std::make_shared<RNHapticFeedback>(ctx, name);
|
|
23
|
+
}
|
|
24
|
+
return nullptr;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class RNHapticFeedbackPackage : public Package {
|
|
29
|
+
public:
|
|
30
|
+
RNHapticFeedbackPackage(Package::Context ctx) : Package(ctx){};
|
|
31
|
+
|
|
32
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
33
|
+
return std::make_unique<RNHapticFeedbackPackageTurboModuleFactoryDelegate>();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import hilog from '@ohos.hilog';
|
|
8
|
+
|
|
9
|
+
class Logger {
|
|
10
|
+
private domain: number;
|
|
11
|
+
private prefix: string;
|
|
12
|
+
private format: string = '%{public}s, %{public}s';
|
|
13
|
+
private isDebug: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* constructor.
|
|
17
|
+
*
|
|
18
|
+
* @param Prefix Identifies the log tag.
|
|
19
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
20
|
+
*/
|
|
21
|
+
constructor(prefix: string = 'RNCToolbarAndroid', domain: number = 0xFF00, isDebug = false) {
|
|
22
|
+
this.prefix = prefix;
|
|
23
|
+
this.domain = domain;
|
|
24
|
+
this.isDebug = isDebug;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
debug(...args: string[]): void {
|
|
28
|
+
if (this.isDebug) {
|
|
29
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
info(...args: string[]): void {
|
|
34
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
warn(...args: string[]): void {
|
|
38
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
error(...args: string[]): void {
|
|
42
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default new Logger('RNTextSizeTurboModule', 0xFF00, false)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
8
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
9
|
+
import { TM } from "./generated/ts";
|
|
10
|
+
import { RNHapticFeedbackTurboModule } from './RNHapticFeedbackTurboModule';
|
|
11
|
+
|
|
12
|
+
class RNHapticFeedbackTurboModuleFactory extends TurboModulesFactory {
|
|
13
|
+
createTurboModule(name: string): TurboModule | null {
|
|
14
|
+
if (this.hasTurboModule(name)) {
|
|
15
|
+
return new RNHapticFeedbackTurboModule(this.ctx);
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
hasTurboModule(name: string): boolean {
|
|
21
|
+
return name === TM.RNHapticFeedback.NAME;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class RNHapticFeedbackPackage extends RNPackage {
|
|
26
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
27
|
+
return new RNHapticFeedbackTurboModuleFactory(ctx);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
8
|
+
import { TM } from "./generated/ts";
|
|
9
|
+
import Logger from './Logger';
|
|
10
|
+
import vibrator from '@ohos.vibrator';
|
|
11
|
+
import audio from '@ohos.multimedia.audio';
|
|
12
|
+
import { BusinessError } from '@ohos.base';
|
|
13
|
+
import common from '@ohos.app.ability.common';
|
|
14
|
+
|
|
15
|
+
export class RNHapticFeedbackTurboModule extends TurboModule implements TM.RNHapticFeedback.Spec {
|
|
16
|
+
private context: common.UIAbilityContext
|
|
17
|
+
constructor(ctx: TurboModuleContext) {
|
|
18
|
+
super(ctx);
|
|
19
|
+
this.context = ctx.uiAbilityContext
|
|
20
|
+
}
|
|
21
|
+
public trigger(type: string, options?: { enableVibrateFallback: boolean,ignoreAndroidSystemSettings:boolean }): void {
|
|
22
|
+
let ignoreHOSSystemSettingsVal = options?.ignoreAndroidSystemSettings || false
|
|
23
|
+
let singleObj = {
|
|
24
|
+
impactLight: { type: 'preset', effectId: 'haptic.effect.hard', intensity: 30 },
|
|
25
|
+
impactMedium: { type: 'preset', effectId: 'haptic.effect.hard', intensity: 60 },
|
|
26
|
+
impactHeavy: { type: 'preset', effectId: 'haptic.effect.hard' },
|
|
27
|
+
rigid: { type: 'preset', effectId: 'haptic.effect.sharp' },
|
|
28
|
+
soft: { type: 'preset', effectId: 'haptic.effect.soft' },
|
|
29
|
+
selection: { type: 'preset', effectId: 'haptic.effect.sharp', intensity: 50 },
|
|
30
|
+
effectClick: { type: 'preset', effectId: 'haptic.effect.soft', intensity: 60 },
|
|
31
|
+
effectHeavyClick: { type: 'preset', effectId: 'haptic.effect.soft', intensity: 80 },
|
|
32
|
+
effectTick: { type: 'preset', effectId: 'haptic.effect.soft', intensity: 70 },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let constantObj={
|
|
36
|
+
clockTick:{type: 'time',duration:4},
|
|
37
|
+
contextClick:{type: 'time',duration:6},
|
|
38
|
+
keyboardPress:{type: 'time',duration:3},
|
|
39
|
+
keyboardRelease:{type: 'time',duration:7},
|
|
40
|
+
keyboardTap:{type: 'time',duration:3},
|
|
41
|
+
longPress:{type: 'time',duration:0},
|
|
42
|
+
textHandleMove:{type: 'time',duration:9},
|
|
43
|
+
virtualKey:{type: 'time',duration:1},
|
|
44
|
+
virtualKeyRelease:{type: 'time',duration:8},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let multipleObj = {
|
|
48
|
+
notificationSuccess: { type: 'file' },
|
|
49
|
+
notificationWarning: { type: 'file' },
|
|
50
|
+
notificationError: { type: 'file' },
|
|
51
|
+
effectDoubleClick: { type: 'file' },
|
|
52
|
+
}
|
|
53
|
+
let audioManager = audio.getAudioManager();
|
|
54
|
+
let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager();
|
|
55
|
+
try {
|
|
56
|
+
let audioVolumeGroupManager: audio.AudioVolumeGroupManager =
|
|
57
|
+
audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID);
|
|
58
|
+
Logger.info(`Get audioVolumeGroupManager success.`);
|
|
59
|
+
let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync()
|
|
60
|
+
let isVolumeOn = value != 0
|
|
61
|
+
let isVibrateMode = value == 1
|
|
62
|
+
Logger.info(`Indicate that the ringer mode is obtained ${value}. finalBollen:${ignoreHOSSystemSettingsVal ==
|
|
63
|
+
false && !(isVolumeOn || isVibrateMode)} isVolumeOn:${isVolumeOn} isVibrateMode:${isVibrateMode}`);
|
|
64
|
+
if (ignoreHOSSystemSettingsVal == false && !(isVolumeOn || isVibrateMode)) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (singleObj[type]) {
|
|
68
|
+
try {
|
|
69
|
+
vibrator.startVibration({
|
|
70
|
+
type: singleObj[type].type,
|
|
71
|
+
effectId: singleObj[type].effectId,
|
|
72
|
+
count: 1,
|
|
73
|
+
intensity: singleObj[type].intensity || 100
|
|
74
|
+
}, {
|
|
75
|
+
id: 0,
|
|
76
|
+
usage: 'unknown'
|
|
77
|
+
}, (error: BusinessError) => {
|
|
78
|
+
if (error) {
|
|
79
|
+
Logger.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
Logger.info('Succeed in starting vibration');
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
let e: BusinessError = err as BusinessError;
|
|
86
|
+
Logger.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
|
|
87
|
+
}
|
|
88
|
+
} else if (multipleObj[type]) {
|
|
89
|
+
let rawFd = this.context.resourceManager.getRawFdSync(`${type}.json`);
|
|
90
|
+
try {
|
|
91
|
+
vibrator.startVibration({
|
|
92
|
+
type: multipleObj[type].type,
|
|
93
|
+
hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length }
|
|
94
|
+
}, {
|
|
95
|
+
id: 0,
|
|
96
|
+
usage: 'unknown'
|
|
97
|
+
}).then(() => {
|
|
98
|
+
Logger.info(`Succeed in starting vibration!!!!!! type:${type}.json fd:${rawFd.fd} offset: ${rawFd.offset} length: ${rawFd.length}`);
|
|
99
|
+
}, (error: BusinessError) => {
|
|
100
|
+
Logger.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
|
|
101
|
+
});
|
|
102
|
+
} catch (err) {
|
|
103
|
+
let e: BusinessError = err as BusinessError;
|
|
104
|
+
Logger.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
|
|
105
|
+
}
|
|
106
|
+
this.context.resourceManager.closeRawFdSync(`${type}.json`)
|
|
107
|
+
}else if(constantObj[type]){
|
|
108
|
+
try {
|
|
109
|
+
vibrator.startVibration({
|
|
110
|
+
type: constantObj[type].type,
|
|
111
|
+
duration: constantObj[type].duration
|
|
112
|
+
}, {
|
|
113
|
+
id: 0,
|
|
114
|
+
usage: 'unknown'
|
|
115
|
+
}).then(() => {
|
|
116
|
+
Logger.info('Succeed in starting vibration');
|
|
117
|
+
}, (error: BusinessError) => {
|
|
118
|
+
Logger.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
let e: BusinessError = err as BusinessError;
|
|
122
|
+
Logger.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
|
|
123
|
+
}
|
|
124
|
+
}else{
|
|
125
|
+
try {
|
|
126
|
+
vibrator.startVibration({
|
|
127
|
+
type: 'preset',
|
|
128
|
+
effectId: 'haptic.effect.sharp',
|
|
129
|
+
count: 1,
|
|
130
|
+
intensity: 50
|
|
131
|
+
}, {
|
|
132
|
+
id: 0,
|
|
133
|
+
usage: 'unknown'
|
|
134
|
+
}, (error: BusinessError) => {
|
|
135
|
+
if (error) {
|
|
136
|
+
Logger.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
Logger.info('Succeed in starting vibration');
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
let e: BusinessError = err as BusinessError;
|
|
143
|
+
Logger.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
let error = err as BusinessError;
|
|
148
|
+
Logger.error(`Failed to get audioVolumeGroupManager, error: ${error}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export * as RNC from "./components/ts"
|
|
9
|
+
export * as TM from "./turboModules/ts"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export namespace RNHapticFeedback {
|
|
11
|
+
export const NAME = 'RNHapticFeedback' as const
|
|
12
|
+
|
|
13
|
+
export interface Spec {
|
|
14
|
+
trigger(type: string, options: {enableVibrateFallback?: boolean, ignoreAndroidSystemSettings?: boolean}): void;
|
|
15
|
+
}
|
|
16
|
+
}
|