mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 09:24:17 +08:00
[add] AccessibilityInfo and DeviceInfo stubs
This commit is contained in:
@@ -63,13 +63,13 @@
|
||||
"website"
|
||||
],
|
||||
"lint-staged": {
|
||||
"packages/react-native-web/src/index.js": [
|
||||
"node ./scripts/babel/createModuleMap.js"
|
||||
],
|
||||
"**/*.js": [
|
||||
"prettier --write",
|
||||
"git update-index --again",
|
||||
"eslint"
|
||||
],
|
||||
"packages/react-native-web/src/index.js": [
|
||||
"node ./scripts/babel/createModuleMap.js"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
|
||||
module.exports = {
|
||||
ART: true,
|
||||
AccessibilityInfo: true,
|
||||
ActivityIndicator: true,
|
||||
Animated: true,
|
||||
AppRegistry: true,
|
||||
@@ -11,6 +12,7 @@ module.exports = {
|
||||
CheckBox: true,
|
||||
Clipboard: true,
|
||||
ColorPropType: true,
|
||||
DeviceInfo: true,
|
||||
Dimensions: true,
|
||||
Easing: true,
|
||||
EdgeInsetsPropType: true,
|
||||
|
||||
52
packages/react-native-web/src/exports/AccessibilityInfo/index.js
vendored
Normal file
52
packages/react-native-web/src/exports/AccessibilityInfo/index.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
function emptyFunction() {}
|
||||
|
||||
const AccessibilityInfo = {
|
||||
/**
|
||||
* Query whether a screen reader is currently enabled.
|
||||
*
|
||||
* Returns a promise which resolves to a boolean.
|
||||
* The result is `true` when a screen reader is enabled and `false` otherwise.
|
||||
*/
|
||||
fetch: function(): Promise<*> {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(true);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Add an event handler. Supported events:
|
||||
*/
|
||||
addEventListener: function(eventName: string, handler: Function): Object {
|
||||
return {
|
||||
remove: emptyFunction
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Set accessibility focus to a react component.
|
||||
*/
|
||||
setAccessibilityFocus: function(reactTag: number): void {},
|
||||
|
||||
/**
|
||||
* Post a string to be announced by the screen reader.
|
||||
*/
|
||||
announceForAccessibility: function(announcement: string): void {},
|
||||
|
||||
/**
|
||||
* Remove an event handler.
|
||||
*/
|
||||
removeEventListener: function(eventName: string, handler: Function): void {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
export default AccessibilityInfo;
|
||||
54
packages/react-native-web/src/exports/DeviceInfo/index.js
vendored
Normal file
54
packages/react-native-web/src/exports/DeviceInfo/index.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Nicolas Gallagher.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
||||
import Dimensions from '../Dimensions';
|
||||
|
||||
const DeviceInfo = {
|
||||
Dimensions: {
|
||||
get windowPhysicalPixels() {
|
||||
const { width, height, fontScale, scale } = Dimensions.get('window');
|
||||
return {
|
||||
width: width * scale,
|
||||
height: height * scale,
|
||||
scale,
|
||||
fontScale
|
||||
};
|
||||
},
|
||||
get screenPhysicalPixels() {
|
||||
const { width, height, fontScale, scale } = Dimensions.get('screen');
|
||||
return {
|
||||
width: width * scale,
|
||||
height: height * scale,
|
||||
scale,
|
||||
fontScale
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
get locale() {
|
||||
if (canUseDOM) {
|
||||
if (window.navigator.languages) {
|
||||
return window.navigator.languages[0];
|
||||
} else {
|
||||
return window.navigator.language;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get totalMemory() {
|
||||
return canUseDOM ? window.navigator.deviceMemory : undefined;
|
||||
},
|
||||
|
||||
get userAgent() {
|
||||
return canUseDOM ? window.navigator.userAgent : '';
|
||||
}
|
||||
};
|
||||
|
||||
export default DeviceInfo;
|
||||
6
packages/react-native-web/src/index.js
vendored
6
packages/react-native-web/src/index.js
vendored
@@ -8,12 +8,14 @@ import TextPropTypes from './exports/TextPropTypes';
|
||||
import ViewPropTypes from './exports/ViewPropTypes';
|
||||
|
||||
// APIs
|
||||
import AccessibilityInfo from './exports/AccessibilityInfo';
|
||||
import Animated from './exports/Animated';
|
||||
import AppRegistry from './exports/AppRegistry';
|
||||
import AppState from './exports/AppState';
|
||||
import AsyncStorage from './exports/AsyncStorage';
|
||||
import BackHandler from './exports/BackHandler';
|
||||
import Clipboard from './exports/Clipboard';
|
||||
import DeviceInfo from './exports/DeviceInfo';
|
||||
import Dimensions from './exports/Dimensions';
|
||||
import Easing from './exports/Easing';
|
||||
import I18nManager from './exports/I18nManager';
|
||||
@@ -75,12 +77,14 @@ export {
|
||||
TextPropTypes,
|
||||
ViewPropTypes,
|
||||
// APIs
|
||||
AccessibilityInfo,
|
||||
Animated,
|
||||
AppRegistry,
|
||||
AppState,
|
||||
AsyncStorage,
|
||||
BackHandler,
|
||||
Clipboard,
|
||||
DeviceInfo,
|
||||
Dimensions,
|
||||
Easing,
|
||||
I18nManager,
|
||||
@@ -141,12 +145,14 @@ const ReactNative = {
|
||||
TextPropTypes,
|
||||
ViewPropTypes,
|
||||
// APIs
|
||||
AccessibilityInfo,
|
||||
Animated,
|
||||
AppRegistry,
|
||||
AppState,
|
||||
AsyncStorage,
|
||||
BackHandler,
|
||||
Clipboard,
|
||||
DeviceInfo,
|
||||
Dimensions,
|
||||
Easing,
|
||||
I18nManager,
|
||||
|
||||
@@ -11,7 +11,7 @@ const getDirectories = source =>
|
||||
|
||||
const packagesDir = path.join(__dirname, '../../packages/');
|
||||
const exportsDir = path.join(packagesDir, 'react-native-web/src/exports');
|
||||
const moduleMapOutfile = path.join(__dirname, 'babel-plugin-react-native-web/src/moduleMap.js');
|
||||
const moduleMapOutfile = path.join(packagesDir, 'babel-plugin-react-native-web/src/moduleMap.js');
|
||||
|
||||
const moduleMap = getDirectories(exportsDir).reduce((acc, curr) => {
|
||||
acc[curr] = true;
|
||||
|
||||
Reference in New Issue
Block a user