-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rn): 新增deviceMotion,accelerometer两个API
- Loading branch information
Showing
19 changed files
with
131 additions
and
34 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
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
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
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,45 @@ | ||
import { Accelerometer } from 'expo' | ||
|
||
const accCase = {} | ||
const intervalMap = { | ||
game: 29, | ||
ui: 60, | ||
normal: 200 | ||
} | ||
|
||
function onAccelerometerChange (fnc) { | ||
accCase.callback = fnc | ||
} | ||
|
||
function startAccelerometer (object) { | ||
const { interval, success, fail, complete } = object | ||
accCase.interval = interval | ||
try { | ||
accCase.listener = Accelerometer.addListener(accCase.callback) | ||
success && success() | ||
complete && complete() | ||
} catch (error) { | ||
fail && fail() | ||
complete && complete() | ||
} | ||
Accelerometer.setUpdateInterval(intervalMap[interval]) | ||
} | ||
|
||
function stopAccelerometer (object) { | ||
const { success, fail, complete } = object | ||
try { | ||
accCase.listener.remove() | ||
accCase.listener = null | ||
success && success() | ||
complete && complete() | ||
} catch (error) { | ||
fail && fail() | ||
complete && complete() | ||
} | ||
} | ||
|
||
export default { | ||
onAccelerometerChange, | ||
startAccelerometer, | ||
stopAccelerometer | ||
} |
File renamed without changes.
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,48 @@ | ||
import { DangerZone } from 'expo' | ||
|
||
const devMotionCase = {} | ||
const intervalMap = { | ||
game: 20, | ||
ui: 60, | ||
normal: 200 | ||
} | ||
|
||
function onDeviceMotionChange (fnc) { | ||
devMotionCase.callback = fnc | ||
} | ||
|
||
function startDeviceMotionListening (object = {}) { | ||
const { interval = 'normal', success, fail, complete } = object | ||
devMotionCase.interval = interval | ||
try { | ||
devMotionCase.listener = DangerZone.DeviceMotion.addListener((res) => { | ||
const { rotation } = res | ||
devMotionCase.callback && devMotionCase.callback(rotation) | ||
}) | ||
success && success() | ||
complete && complete() | ||
} catch (error) { | ||
fail && fail() | ||
complete && complete() | ||
} | ||
DangerZone.DeviceMotion.setUpdateInterval(intervalMap[interval] || intervalMap.normal) | ||
} | ||
|
||
function stopDeviceMotionListening (object = {}) { | ||
const { success, fail, complete } = object | ||
try { | ||
devMotionCase.listener.remove() | ||
devMotionCase.listener = null | ||
success && success() | ||
complete && complete() | ||
} catch (error) { | ||
fail && fail() | ||
complete && complete() | ||
} | ||
} | ||
|
||
export default { | ||
onDeviceMotionChange, | ||
startDeviceMotionListening, | ||
stopDeviceMotionListening | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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