-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'vincentriemer/master' into slider
- Loading branch information
Showing
13 changed files
with
440 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"projectName": "react-native-dom", | ||
"projectOwner": "vincentriemer", | ||
"repoType": "github", | ||
"repoHost": "https://github.com", | ||
"files": [ | ||
"README.md" | ||
], | ||
"imageSize": 100, | ||
"commit": false, | ||
"contributors": [ | ||
{ | ||
"login": "vincentriemer", | ||
"name": "Vincent Riemer", | ||
"avatar_url": "https://avatars2.githubusercontent.com/u/1398555?v=4", | ||
"profile": "http://vincentriemer.com", | ||
"contributions": [ | ||
"code", | ||
"bug", | ||
"doc", | ||
"example", | ||
"ideas", | ||
"infra", | ||
"platform", | ||
"talk" | ||
] | ||
}, | ||
{ | ||
"login": "joegoodall1", | ||
"name": "Joe Goodall", | ||
"avatar_url": "https://avatars0.githubusercontent.com/u/8888799?v=4", | ||
"profile": "https://uk.linkedin.com/in/joegoodall", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "frosato-ekino", | ||
"name": "François Rosato", | ||
"avatar_url": "https://avatars3.githubusercontent.com/u/31624379?v=4", | ||
"profile": "https://github.com/frosato-ekino", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "motiz88", | ||
"name": "Moti Zilberman", | ||
"avatar_url": "https://avatars2.githubusercontent.com/u/2246565?v=4", | ||
"profile": "https://github.com/motiz88", | ||
"contributions": [ | ||
"code", | ||
"doc" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/vincentriemer/react-native-dom/compare/v0.1.2...v0.2.0) (2018-06-03) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* **flow:** Fix flow errors ([0304c11](https://github.com/vincentriemer/react-native-dom/commit/0304c11)) | ||
* **RCTBridge:** Silence bundle progress parse errors ([62ddca5](https://github.com/vincentriemer/react-native-dom/commit/62ddca5)) | ||
* **RCTPropsAnimatedNode:** Fix iteration over prop config ([cdabeb5](https://github.com/vincentriemer/react-native-dom/commit/cdabeb5)) | ||
|
||
|
||
### Features | ||
|
||
* **AsyncLocalStorage:** Add clear method to native AsyncLocalStorage ([6e72487](https://github.com/vincentriemer/react-native-dom/commit/6e72487)) | ||
* **RCTImage:** Add Image resizeMode=repeat ([3d441ca](https://github.com/vincentriemer/react-native-dom/commit/3d441ca)) | ||
* **RCTRootView:** Begin work on decoupling the root view from the document's body ([79a02bc](https://github.com/vincentriemer/react-native-dom/commit/79a02bc)) | ||
* **RCTVibration:** Add Vibration API ([9277d56](https://github.com/vincentriemer/react-native-dom/commit/9277d56)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/vincentriemer/react-native-dom/compare/v0.1.2...v0.2.0) (2018-06-03) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* **flow:** Fix flow errors ([0304c11](https://github.com/vincentriemer/react-native-dom/commit/0304c11)) | ||
* **RCTBridge:** Silence bundle progress parse errors ([62ddca5](https://github.com/vincentriemer/react-native-dom/commit/62ddca5)) | ||
* **RCTPropsAnimatedNode:** Fix iteration over prop config ([cdabeb5](https://github.com/vincentriemer/react-native-dom/commit/cdabeb5)) | ||
|
||
|
||
### Features | ||
|
||
* **AsyncLocalStorage:** Add clear method to native AsyncLocalStorage ([6e72487](https://github.com/vincentriemer/react-native-dom/commit/6e72487)) | ||
* **RCTImage:** Add Image resizeMode=repeat ([3d441ca](https://github.com/vincentriemer/react-native-dom/commit/3d441ca)) | ||
* **RCTRootView:** Begin work on decoupling the root view from the document's body ([79a02bc](https://github.com/vincentriemer/react-native-dom/commit/79a02bc)) | ||
* **RCTVibration:** Add Vibration API ([9277d56](https://github.com/vincentriemer/react-native-dom/commit/9277d56)) |
114 changes: 114 additions & 0 deletions
114
packages/react-native-dom/Libraries/Vibration/Vibration.dom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @providesModule Vibration | ||
* @flow | ||
* @jsdoc | ||
*/ | ||
"use strict"; | ||
|
||
var RCTVibration = require("NativeModules").Vibration; | ||
var Platform = require("Platform"); | ||
|
||
/** | ||
* Vibration API | ||
* | ||
* See https://facebook.github.io/react-native/docs/vibration.html | ||
*/ | ||
|
||
var _vibrating: boolean = false; | ||
var _id: number = 0; // _id is necessary to prevent race condition. | ||
|
||
function vibrateByPattern(pattern: Array<number>, repeat: boolean = false) { | ||
if (_vibrating) { | ||
return; | ||
} | ||
_vibrating = true; | ||
if (pattern[0] === 0) { | ||
RCTVibration.vibrate(); | ||
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; | ||
} | ||
RCTVibration.vibrate(); | ||
if (nextIndex >= pattern.length) { | ||
if (repeat) { | ||
nextIndex = 0; | ||
} else { | ||
_vibrating = false; | ||
return; | ||
} | ||
} | ||
setTimeout( | ||
() => vibrateScheduler(id, pattern, repeat, nextIndex + 1), | ||
pattern[nextIndex] | ||
); | ||
} | ||
|
||
var Vibration = { | ||
/** | ||
* Trigger a vibration with specified `pattern`. | ||
* | ||
* See https://facebook.github.io/react-native/docs/vibration.html#vibrate | ||
*/ | ||
vibrate: function( | ||
pattern: number | Array<number> = 400, | ||
repeat: boolean = false | ||
) { | ||
if (Platform.OS === "android" || Platform.OS === "dom") { | ||
if (typeof pattern === "number") { | ||
RCTVibration.vibrate(pattern); | ||
} else if (Array.isArray(pattern)) { | ||
if (Platform.OS === "android") { | ||
RCTVibration.vibrateByPattern(pattern, repeat ? 0 : -1); | ||
} else { | ||
RCTVibration.vibrateByPattern(pattern, repeat); | ||
} | ||
} else { | ||
throw new Error("Vibration pattern should be a number or array"); | ||
} | ||
} else { | ||
if (_vibrating) { | ||
return; | ||
} | ||
if (typeof pattern === "number") { | ||
RCTVibration.vibrate(); | ||
} else if (Array.isArray(pattern)) { | ||
vibrateByPattern(pattern, repeat); | ||
} else { | ||
throw new Error("Vibration pattern should be a number or array"); | ||
} | ||
} | ||
}, | ||
/** | ||
* Stop vibration | ||
* | ||
* See https://facebook.github.io/react-native/docs/vibration.html#cancel | ||
*/ | ||
cancel: function() { | ||
if (Platform.OS === "ios") { | ||
_vibrating = false; | ||
} else { | ||
RCTVibration.cancel(); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = Vibration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/react-native-dom/ReactDom/modules/RCTVibration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @providesModule RCTVibration | ||
* @flow | ||
*/ | ||
|
||
import RCTBridge, { | ||
RCTFunctionTypeNormal, | ||
RCT_EXPORT_METHOD, | ||
RCT_EXPORT_MODULE | ||
} from "RCTBridge"; | ||
|
||
@RCT_EXPORT_MODULE("RCTVibration") | ||
class RCTVibration { | ||
_intervalHandle: IntervalID; | ||
|
||
@RCT_EXPORT_METHOD(RCTFunctionTypeNormal) | ||
vibrateByPattern(pattern: Array<number>, repeat: boolean = false) { | ||
if (!navigator.vibrate) { | ||
return; | ||
} | ||
// Keep flow happy re: possible mutations of navigator | ||
const vibrate = navigator.vibrate.bind(navigator); | ||
vibrate(pattern); | ||
clearInterval(this._intervalHandle); | ||
if (repeat) { | ||
const patternDuration = pattern.reduce((a, b) => a + b, 0); | ||
this._intervalHandle = setInterval( | ||
() => vibrate(pattern), | ||
patternDuration | ||
); | ||
} | ||
} | ||
|
||
@RCT_EXPORT_METHOD(RCTFunctionTypeNormal) | ||
vibrate(duration: number) { | ||
if (!navigator.vibrate) { | ||
return; | ||
} | ||
navigator.vibrate(duration); | ||
clearInterval(this._intervalHandle); | ||
} | ||
|
||
@RCT_EXPORT_METHOD(RCTFunctionTypeNormal) | ||
cancel() { | ||
this.vibrate(0); | ||
} | ||
} | ||
|
||
export default RCTVibration; |
Oops, something went wrong.