[RCTVibration] Basic Vibration API

Summary:
* Exposed as `VibrationIOS.vibrate();`
* Included a UI Explorer example.
* Vibration patterns are currently unsupported as there is no API to produce a vibration of less than 1 second on iOS.
Closes https://github.com/facebook/react-native/pull/154
Github Author: Joe Stanton <joe.stanton@red-badger.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
Joe Stanton 2015-03-16 21:02:57 -07:00
parent e59dcb3a60
commit f8ab8415d5
8 changed files with 376 additions and 0 deletions

View File

@ -19,6 +19,7 @@
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */; };
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -78,6 +79,13 @@
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTActionSheet;
};
D85B829B1AB6D5CE003F4FE2 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
remoteInfo = RCTVibration;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
@ -98,6 +106,7 @@
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../../Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = ../../Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -112,6 +121,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */,
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */,
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */,
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */,
@ -145,6 +155,7 @@
1316A21D1AA397F400C0188E /* Libraries */ = {
isa = PBXGroup;
children = (
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */,
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */,
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */,
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */,
@ -244,6 +255,14 @@
name = Products;
sourceTree = "<group>";
};
D85B82921AB6D5CE003F4FE2 /* Products */ = {
isa = PBXGroup;
children = (
D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -333,6 +352,10 @@
ProductGroup = 13417FEB1AA914B8003F314A /* Products */;
ProjectRef = 13417FEA1AA914B8003F314A /* RCTText.xcodeproj */;
},
{
ProductGroup = D85B82921AB6D5CE003F4FE2 /* Products */;
ProjectRef = D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */;
},
{
ProductGroup = 13417FFB1AA91531003F314A /* Products */;
ProjectRef = 13417FFA1AA91531003F314A /* ReactKit.xcodeproj */;
@ -396,6 +419,13 @@
remoteRef = 147CED4A1AB34F8C00DA3E4C /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTVibration.a;
remoteRef = D85B829B1AB6D5CE003F4FE2 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */

View File

@ -47,6 +47,7 @@ var EXAMPLES = [
require('./AdSupportIOSExample'),
require('./AppStateExample'),
require('./ActionSheetIOSExample'),
require('./VibrationIOSExample'),
];
var UIExplorerList = React.createClass({

View File

@ -0,0 +1,42 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*/
'use strict';
var React = require('react-native');
var {
StyleSheet,
View,
Text,
TouchableHighlight,
VibrationIOS
} = React;
exports.framework = 'React';
exports.title = 'VibrationIOS';
exports.description = 'Vibration API for iOS';
exports.examples = [{
title: 'VibrationIOS.vibrate()',
render() {
return (
<TouchableHighlight
style={styles.wrapper}
onPress={() => VibrationIOS.vibrate()}>
<View style={styles.button}>
<Text>Vibrate</Text>
</View>
</TouchableHighlight>
);
},
}];
var styles = StyleSheet.create({
wrapper: {
borderRadius: 5,
marginBottom: 5,
},
button: {
backgroundColor: '#eeeeee',
padding: 10,
},
});

View File

@ -0,0 +1,7 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import "RCTBridgeModule.h"
@interface RCTVibration : NSObject <RCTBridgeModule>
@end

View File

@ -0,0 +1,15 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import "RCTVibration.h"
#import <AudioToolbox/AudioToolbox.h>
@implementation RCTVibration
- (void)vibrate
{
RCT_EXPORT();
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
@end

View File

@ -0,0 +1,248 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
832C819C1AAF6E1A007FA2F7 /* RCTVibration.m in Sources */ = {isa = PBXBuildFile; fileRef = 832C819B1AAF6E1A007FA2F7 /* RCTVibration.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
832C817E1AAF6DEF007FA2F7 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
832C81801AAF6DEF007FA2F7 /* libRCTVibration.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTVibration.a; sourceTree = BUILT_PRODUCTS_DIR; };
832C819A1AAF6E1A007FA2F7 /* RCTVibration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVibration.h; sourceTree = "<group>"; };
832C819B1AAF6E1A007FA2F7 /* RCTVibration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVibration.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
832C817D1AAF6DEF007FA2F7 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
832C81771AAF6DEF007FA2F7 = {
isa = PBXGroup;
children = (
832C819A1AAF6E1A007FA2F7 /* RCTVibration.h */,
832C819B1AAF6E1A007FA2F7 /* RCTVibration.m */,
832C81811AAF6DEF007FA2F7 /* Products */,
);
sourceTree = "<group>";
};
832C81811AAF6DEF007FA2F7 /* Products */ = {
isa = PBXGroup;
children = (
832C81801AAF6DEF007FA2F7 /* libRCTVibration.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
832C817F1AAF6DEF007FA2F7 /* RCTVibration */ = {
isa = PBXNativeTarget;
buildConfigurationList = 832C81941AAF6DF0007FA2F7 /* Build configuration list for PBXNativeTarget "RCTVibration" */;
buildPhases = (
832C817C1AAF6DEF007FA2F7 /* Sources */,
832C817D1AAF6DEF007FA2F7 /* Frameworks */,
832C817E1AAF6DEF007FA2F7 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RCTVibration;
productName = RCTVibration;
productReference = 832C81801AAF6DEF007FA2F7 /* libRCTVibration.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
832C81781AAF6DEF007FA2F7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0620;
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
832C817F1AAF6DEF007FA2F7 = {
CreatedOnToolsVersion = 6.2;
};
};
};
buildConfigurationList = 832C817B1AAF6DEF007FA2F7 /* Build configuration list for PBXProject "RCTVibration" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 832C81771AAF6DEF007FA2F7;
productRefGroup = 832C81811AAF6DEF007FA2F7 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
832C817F1AAF6DEF007FA2F7 /* RCTVibration */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
832C817C1AAF6DEF007FA2F7 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
832C819C1AAF6E1A007FA2F7 /* RCTVibration.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
832C81921AAF6DF0007FA2F7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../ReactKit/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
832C81931AAF6DF0007FA2F7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../ReactKit/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
832C81951AAF6DF0007FA2F7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
832C81961AAF6DF0007FA2F7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
832C817B1AAF6DEF007FA2F7 /* Build configuration list for PBXProject "RCTVibration" */ = {
isa = XCConfigurationList;
buildConfigurations = (
832C81921AAF6DF0007FA2F7 /* Debug */,
832C81931AAF6DF0007FA2F7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
832C81941AAF6DF0007FA2F7 /* Build configuration list for PBXNativeTarget "RCTVibration" */ = {
isa = XCConfigurationList;
buildConfigurations = (
832C81951AAF6DF0007FA2F7 /* Debug */,
832C81961AAF6DF0007FA2F7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 832C81781AAF6DEF007FA2F7 /* Project object */;
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule VibrationIOS
*/
'use strict';
var {RCTVibration} = require('NativeModules');
var invariant = require('invariant');
/**
* The Vibration API is exposed at `VibrationIOS.vibrate()`. On iOS, calling this
* function will trigger a one second vibration. The vibration is asynchronous
* so this method will return immediately.
*
* There will be no effect on devices that do not support Vibration, eg. the iOS
* simulator.
*
* Vibration patterns are currently unsupported.
*/
var VibrationIOS = {
vibrate: function() {
invariant(
arguments[0] === undefined,
'Vibration patterns not supported.'
);
RCTVibration.vibrate();
}
};
module.exports = VibrationIOS;

View File

@ -38,6 +38,7 @@ var ReactNative = {
TouchableHighlight: require('TouchableHighlight'),
TouchableOpacity: require('TouchableOpacity'),
TouchableWithoutFeedback: require('TouchableWithoutFeedback'),
VibrationIOS: require('VibrationIOS'),
View: require('View'),
WebView: require('WebView'),
invariant: require('invariant'),