This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its 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-local
* @format
*/
'use strict';
import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export interface Spec extends TurboModule {
+getConstants: () => {||};
+vibrate: (pattern: number) => void;
// Android only
+vibrateByPattern: (pattern: Array<number>, repeat: number) => void;
+cancel: () => void;
}
export default (TurboModuleRegistry.getEnforcing<Spec>('Vibration'): Spec);

View File

@ -0,0 +1,12 @@
/*
* Copyright (c) Facebook, Inc. and its 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,57 @@
/*
* Copyright (c) Facebook, Inc. and its 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>)
getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
nativeInvoker:(std::shared_ptr<facebook::react::CallInvoker>)nativeInvoker
perfLogger:(id<RCTTurboModulePerformanceLogger>)perfLogger
{
return std::make_shared<facebook::react::NativeVibrationSpecJSI>(self, jsInvoker, nativeInvoker, perfLogger);
}
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) Facebook, Inc. and its 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,32 @@
/**
* Copyright (c) Facebook, Inc. and its 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) {
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
{"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,48 @@
# Copyright (c) Facebook, Inc. and its 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
else
source[:tag] = "v#{version}"
end
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
folly_version = '2020.01.13.00'
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 = "Facebook, Inc. and its affiliates"
s.platforms = { :ios => "10.0", :tvos => "10.0" }
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
s.source = source
s.source_files = "*.{m,mm}"
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
s.header_dir = "RCTVibration"
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
}
s.frameworks = "AudioToolbox"
s.dependency "Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "ReactCommon/turbomodule/core", version
s.dependency "React-jsi", version
s.dependency "React-Core/RCTVibrationHeaders", version
end

View File

@ -0,0 +1,112 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @jsdoc
*/
'use strict';
import NativeVibration from './NativeVibration';
const Platform = require('../Utilities/Platform');
/**
* Vibration API
*
* See https://reactnative.dev/docs/vibration.html
*/
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);
pattern = pattern.slice(1);
}
if (pattern.length === 0) {
_vibrating = false;
return;
}
setTimeout(() => vibrateScheduler(++_id, pattern, repeat, 1), pattern[0]);
}
function vibrateScheduler(
id,
pattern: Array<number>,
repeat: boolean,
nextIndex: number,
) {
if (!_vibrating || id !== _id) {
return;
}
NativeVibration.vibrate(_default_vibration_length);
if (nextIndex >= pattern.length) {
if (repeat) {
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.html#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.html#cancel
*/
cancel: function() {
if (Platform.OS === 'ios') {
_vibrating = false;
} else {
NativeVibration.cancel();
}
},
};
module.exports = Vibration;