first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
export * from '../../src/private/specs_DEPRECATED/modules/NativeVibration';
import NativeVibration from '../../src/private/specs_DEPRECATED/modules/NativeVibration';
export default NativeVibration;

View File

@@ -0,0 +1,12 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTBridgeModule.h>
@interface RCTVibration : NSObject <RCTBridgeModule>
@end

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTVibration.h>
#import <AudioToolbox/AudioToolbox.h>
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTLog.h>
#import "RCTVibrationPlugins.h"
@interface RCTVibration () <NativeVibrationSpec>
@end
@implementation RCTVibration
RCT_EXPORT_MODULE()
- (void)vibrate
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
RCT_EXPORT_METHOD(vibrate : (double)pattern)
{
[self vibrate];
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeVibrationSpecJSI>(params);
}
RCT_EXPORT_METHOD(vibrateByPattern : (NSArray *)pattern repeat : (double)repeat)
{
RCTLogError(@"Vibration.vibrateByPattern does not have an iOS implementation");
}
RCT_EXPORT_METHOD(cancel)
{
RCTLogError(@"Vibration.cancel does not have an iOS implementation");
}
@end
Class RCTVibrationCls(void)
{
return RCTVibration.class;
}

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
// FB Internal: FBRCTVibrationPlugins.h is autogenerated by the build system.
#import <React/FBRCTVibrationPlugins.h>
#else
// OSS-compatibility layer
#import <Foundation/Foundation.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
#ifdef __cplusplus
extern "C" {
#endif
// RCTTurboModuleManagerDelegate should call this to resolve module classes.
Class RCTVibrationClassProvider(const char *name);
// Lookup functions
Class RCTVibrationCls(void) __attribute__((used));
#ifdef __cplusplus
}
#endif
#pragma GCC diagnostic pop
#endif // RN_DISABLE_OSS_PLUGIN_HEADER

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
// OSS-compatibility layer
#import "RCTVibrationPlugins.h"
#import <string>
#import <unordered_map>
Class RCTVibrationClassProvider(const char *name) {
// Intentionally leak to avoid crashing after static destructors are run.
static const auto sCoreModuleClassMap = new const std::unordered_map<std::string, Class (*)(void)>{
{"Vibration", RCTVibrationCls},
};
auto p = sCoreModuleClassMap->find(name);
if (p != sCoreModuleClassMap->end()) {
auto classFunc = p->second;
return classFunc();
}
return nil;
}
#endif // RN_DISABLE_OSS_PLUGIN_HEADER

View File

@@ -0,0 +1,53 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
header_search_paths = [
"\"${PODS_ROOT}/Headers/Public/ReactCodegen/react/renderer/components\"",
]
Pod::Spec.new do |s|
s.name = "React-RCTVibration"
s.version = version
s.summary = "An API for controlling the vibration hardware of the device."
s.homepage = "https://reactnative.dev/"
s.documentation_url = "https://reactnative.dev/docs/vibration"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.compiler_flags = '-Wno-nullability-completeness'
s.source = source
s.source_files = podspec_sources("*.{m,mm}", "**/*.h")
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
s.header_dir = "RCTVibration"
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')
}
s.frameworks = "AudioToolbox"
s.dependency "React-jsi"
s.dependency "React-Core/RCTVibrationHeaders"
add_dependency(s, "React-RCTFBReactNativeSpec")
add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"])
add_dependency(s, "React-NativeModulesApple")
add_rn_third_party_dependencies(s)
add_rncore_dependency(s)
end

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/**
* The Vibration API is exposed at `Vibration.vibrate()`.
* The vibration is asynchronous so this method will return immediately.
*
* There will be no effect on devices that do not support Vibration, eg. the simulator.
*
* **Note for android**
* add `<uses-permission android:name="android.permission.VIBRATE"/>` to `AndroidManifest.xml`
*
* **Android Usage:**
*
* [0, 500, 200, 500]
* V(0.5s) --wait(0.2s)--> V(0.5s)
*
* [300, 500, 200, 500]
* --wait(0.3s)--> V(0.5s) --wait(0.2s)--> V(0.5s)
*
* **iOS Usage:**
* if first argument is 0, it will not be included in pattern array.
*
* [0, 1000, 2000, 3000]
* V(fixed) --wait(1s)--> V(fixed) --wait(2s)--> V(fixed) --wait(3s)--> V(fixed)
*/
export interface VibrationStatic {
vibrate(pattern?: number | number[], repeat?: boolean): void;
/**
* Stop vibration
*/
cancel(): void;
}
export const Vibration: VibrationStatic;
export type Vibration = VibrationStatic;

View File

@@ -0,0 +1,112 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
import NativeVibration from './NativeVibration';
const Platform = require('../Utilities/Platform').default;
/**
* Vibration API
*
* See https://reactnative.dev/docs/vibration
*/
let _vibrating: boolean = false;
let _id: number = 0; // _id is necessary to prevent race condition.
const _default_vibration_length = 400;
function vibrateByPattern(pattern: Array<number>, repeat: boolean = false) {
if (_vibrating) {
return;
}
_vibrating = true;
if (pattern[0] === 0) {
NativeVibration.vibrate(_default_vibration_length);
// $FlowFixMe[reassign-const]
pattern = pattern.slice(1);
}
if (pattern.length === 0) {
_vibrating = false;
return;
}
setTimeout(() => vibrateScheduler(++_id, pattern, repeat, 1), pattern[0]);
}
function vibrateScheduler(
id: number,
pattern: Array<number>,
repeat: boolean,
nextIndex: number,
) {
if (!_vibrating || id !== _id) {
return;
}
NativeVibration.vibrate(_default_vibration_length);
if (nextIndex >= pattern.length) {
if (repeat) {
// $FlowFixMe[reassign-const]
nextIndex = 0;
} else {
_vibrating = false;
return;
}
}
setTimeout(
() => vibrateScheduler(id, pattern, repeat, nextIndex + 1),
pattern[nextIndex],
);
}
const Vibration = {
/**
* Trigger a vibration with specified `pattern`.
*
* See https://reactnative.dev/docs/vibration#vibrate
*/
vibrate: function (
pattern?: number | Array<number> = _default_vibration_length,
repeat?: boolean = false,
) {
if (Platform.OS === 'android') {
if (typeof pattern === 'number') {
NativeVibration.vibrate(pattern);
} else if (Array.isArray(pattern)) {
NativeVibration.vibrateByPattern(pattern, repeat ? 0 : -1);
} else {
throw new Error('Vibration pattern should be a number or array');
}
} else {
if (_vibrating) {
return;
}
if (typeof pattern === 'number') {
NativeVibration.vibrate(pattern);
} else if (Array.isArray(pattern)) {
vibrateByPattern(pattern, repeat);
} else {
throw new Error('Vibration pattern should be a number or array');
}
}
},
/**
* Stop vibration
*
* See https://reactnative.dev/docs/vibration#cancel
*/
cancel: function () {
if (Platform.OS === 'ios') {
_vibrating = false;
} else {
NativeVibration.cancel();
}
},
};
export default Vibration;