-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1646 from didi/add-api-proxy-v1
Add api proxy v1
- Loading branch information
Showing
10 changed files
with
156 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './index' |
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,62 @@ | ||
import { Keyboard } from 'react-native' | ||
import { successHandle, failHandle } from '../../../common/js' | ||
let hasListener = false | ||
const callbacks = [] | ||
|
||
function keyboardShowListener (e) { | ||
const endCoordinates = e.endCoordinates || {} | ||
// eslint-disable-next-line node/no-callback-literal | ||
callbacks.forEach(cb => cb({ | ||
height: endCoordinates.height | ||
})) | ||
} | ||
function keyboardHideListener (e) { | ||
const endCoordinates = e.endCoordinates || {} | ||
let height | ||
if (__mpx_mode__ === 'ios') { | ||
height = 0 | ||
} else { | ||
height = endCoordinates.height | ||
} | ||
// eslint-disable-next-line node/no-callback-literal | ||
callbacks.forEach(cb => cb({ | ||
height | ||
})) | ||
} | ||
const onKeyboardHeightChange = function (callback) { | ||
if (!hasListener) { | ||
Keyboard.addListener('keyboardDidShow', keyboardShowListener) | ||
Keyboard.addListener('keyboardDidHide', keyboardHideListener) | ||
hasListener = true | ||
} | ||
callbacks.push(callback) | ||
} | ||
const offKeyboardHeightChange = function (callback) { | ||
const index = callbacks.indexOf(callback) | ||
if (index > -1) { | ||
callbacks.splice(index, 1) | ||
} | ||
if (callbacks.length === 0) { | ||
Keyboard.removeAllListeners('keyboardDidShow') | ||
Keyboard.removeAllListeners('keyboardDidHide') | ||
hasListener = false | ||
} | ||
} | ||
|
||
const hideKeyboard = function (options = {}) { | ||
const { success, fail, complete } = options | ||
try { | ||
Keyboard.dismiss() | ||
const result = { errMsg: 'hideKeyboard:ok' } | ||
successHandle(result, success, complete) | ||
} catch (err) { | ||
const result = { errMsg: err.message } | ||
failHandle(result, fail, complete) | ||
} | ||
} | ||
|
||
export { | ||
onKeyboardHeightChange, | ||
offKeyboardHeightChange, | ||
hideKeyboard | ||
} |
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,13 @@ | ||
import { ENV_OBJ, envError } from '../../../common/js' | ||
|
||
const onKeyboardHeightChange = ENV_OBJ.onKeyboardHeightChange || envError('onKeyboardHeightChange') | ||
|
||
const offKeyboardHeightChange = ENV_OBJ.offKeyboardHeightChange || envError('offKeyboardHeightChange') | ||
|
||
const hideKeyboard = ENV_OBJ.hideKeyboard || envError('hideKeyboard') | ||
|
||
export { | ||
onKeyboardHeightChange, | ||
offKeyboardHeightChange, | ||
hideKeyboard | ||
} |
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 @@ | ||
export * from './index.ios' |
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,39 @@ | ||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback' | ||
import { Vibration } from 'react-native' | ||
import { successHandle, failHandle } from '../../../common/js' | ||
|
||
const getType = function (type = 'light') { | ||
return 'impact' + type[0].toUpperCase() + type.substr(1) | ||
} | ||
const vibrateShort = function (options = {}) { | ||
const { type = 'light', success, fail, complete } = options | ||
try { | ||
ReactNativeHapticFeedback.trigger(getType(type), { | ||
ignoreAndroidSystemSettings: true, | ||
enableVibrateFallback: true | ||
}) | ||
const result = { | ||
errMsg: 'vibrateShort:ok' | ||
} | ||
successHandle(result, success, complete) | ||
} catch (e) { | ||
const result = { | ||
errMsg: 'vibrateShort:fail' | ||
} | ||
failHandle(result, fail, complete) | ||
} | ||
} | ||
|
||
const vibrateLong = function (options = {}) { | ||
const { success, complete } = options | ||
Vibration.vibrate(400) | ||
const result = { | ||
errMsg: 'vibrateLong:ok' | ||
} | ||
successHandle(result, success, complete) | ||
} | ||
|
||
export { | ||
vibrateShort, | ||
vibrateLong | ||
} |
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,10 @@ | ||
import { ENV_OBJ, envError } from '../../../common/js' | ||
|
||
const vibrateShort = ENV_OBJ.vibrateShort || envError('vibrateShort') | ||
|
||
const vibrateLong = ENV_OBJ.vibrateLong || envError('vibrateLong') | ||
|
||
export { | ||
vibrateShort, | ||
vibrateLong | ||
} |
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