-
Notifications
You must be signed in to change notification settings - Fork 375
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 #1474 from didi/feat-react-api-proxy
Feat react api proxy
- Loading branch information
Showing
31 changed files
with
516 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './index.web' |
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.web' |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/clipboard-data/index.android.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 @@ | ||
export * from './rnClipboard' |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/clipboard-data/index.ios.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 @@ | ||
export * from './rnClipboard' |
41 changes: 41 additions & 0 deletions
41
packages/api-proxy/src/platform/api/clipboard-data/rnClipboard.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,41 @@ | ||
import Clipboard from '@react-native-clipboard/clipboard' | ||
import { webHandleSuccess, webHandleFail } from '../../../common/js/web' | ||
import { type } from '@mpxjs/utils' | ||
const setClipboardData = function (options) { | ||
const { data, success, fail, complete } = options | ||
if (!data || type(data) !== 'String') { | ||
const errStr = !data ? 'parameter.data should be String instead of Undefined;' : `parameter.data should be String instead of ${type(data)};` | ||
const result = { | ||
errno: 1001, | ||
errMsg: errStr | ||
} | ||
webHandleFail(result, fail, complete) | ||
return | ||
} | ||
Clipboard.setString(data) | ||
const result = { | ||
errMsg: 'setClipboardData:ok' | ||
} | ||
webHandleSuccess(result, success, complete) | ||
} | ||
|
||
const getClipboardData = function (options) { | ||
const { success, fail, complete } = options | ||
Clipboard.getString().then((data) => { | ||
const result = { | ||
data, | ||
errMsg: 'getClipboardData:ok' | ||
} | ||
webHandleSuccess(result, success, complete) | ||
}).catch(() => { | ||
const result = { | ||
errMsg: 'setClipboardData:fail' | ||
} | ||
webHandleFail(result, fail, complete) | ||
}) | ||
} | ||
|
||
export { | ||
setClipboardData, | ||
getClipboardData | ||
} |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/device/network/index.android.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 @@ | ||
export * from './rnNetwork' |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/device/network/index.ios.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 @@ | ||
export * from './rnNetwork' |
59 changes: 59 additions & 0 deletions
59
packages/api-proxy/src/platform/api/device/network/rnNetwork.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,59 @@ | ||
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../../common/js' | ||
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo' | ||
|
||
let _unsubscribe = null | ||
const _callbacks = new Set() | ||
const getConnectionType = function (connectionInfo) { | ||
let type = 'unknown' | ||
if (connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) { | ||
type = connectionInfo.details.cellularGeneration | ||
} else if (connectionInfo.type === NetInfoStateType.wifi || connectionInfo.type === NetInfoStateType.none) { | ||
type = connectionInfo.type | ||
} | ||
return type | ||
} | ||
|
||
const getNetworkType = function (options) { | ||
const { success, fail, complete } = options | ||
NetInfo.fetch().then((connectionInfo) => { | ||
const result = { | ||
networkType: getConnectionType(connectionInfo), | ||
errMsg: 'getNetworkType:ok' | ||
} | ||
defineUnsupportedProps(result, ['signalStrength', 'hasSystemProxy']) | ||
webHandleSuccess(result, success, complete) | ||
}).catch((err) => { | ||
const result = { | ||
errMsg: err.message | ||
} | ||
webHandleFail(result, fail, complete) | ||
}) | ||
} | ||
|
||
const onNetworkStatusChange = function (callback) { | ||
_callbacks.add(callback) | ||
if (!_unsubscribe) { | ||
_unsubscribe = NetInfo.addEventListener((connectionInfo) => { | ||
_callbacks.forEach(cb => { | ||
const { isConnected } = connectionInfo | ||
// eslint-disable-next-line node/no-callback-literal | ||
cb && cb({ isConnected, networkType: getConnectionType(connectionInfo) }) | ||
}) | ||
}) | ||
} | ||
} | ||
const offNetworkStatusChange = function (callback) { | ||
if (callback && typeof callback === 'function') { | ||
_callbacks.delete(callback) | ||
} else if (callback === undefined) { | ||
_callbacks.clear() | ||
_unsubscribe && _unsubscribe() | ||
_unsubscribe = null | ||
} | ||
} | ||
|
||
export { | ||
getNetworkType, | ||
offNetworkStatusChange, | ||
onNetworkStatusChange | ||
} |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/make-phone-call/index.andriod.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 @@ | ||
export * from './rnMakePhone' |
1 change: 1 addition & 0 deletions
1
packages/api-proxy/src/platform/api/make-phone-call/index.ios.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 @@ | ||
export * from './rnMakePhone' |
27 changes: 27 additions & 0 deletions
27
packages/api-proxy/src/platform/api/make-phone-call/rnMakePhone.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,27 @@ | ||
import { webHandleSuccess, webHandleFail } from '../../../common/js' | ||
import { Linking } from 'react-native' | ||
|
||
const makePhoneCall = function (options) { | ||
const { | ||
phoneNumber = '', | ||
success = null, | ||
fail = null, | ||
complete = null | ||
} = options | ||
|
||
Linking.openURL(`tel:${phoneNumber}`).then(() => { | ||
const result = { | ||
errMsg: 'makePhoneCall:ok' | ||
} | ||
webHandleSuccess(result, success, complete) | ||
}).catch(() => { | ||
const result = { | ||
errMsg: 'makePhoneCall:fail cancel' | ||
} | ||
webHandleFail(result, fail, complete) | ||
}) | ||
} | ||
|
||
export { | ||
makePhoneCall | ||
} |
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.web' |
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.web' |
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.web' |
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.web' |
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 './rnStorage' |
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 './rnStorage' |
Oops, something went wrong.