Move React Native platform files back

These files are really only related to the platform itself and not
the React integration so I'll move them back.
This commit is contained in:
Sebastian Markbage
2016-04-20 03:35:30 +01:00
parent 6c885d28c5
commit fe395def65
7 changed files with 0 additions and 879 deletions
-364
View File
@@ -1,364 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule YellowBox
* @flow
*/
'use strict';
const EventEmitter = require('EventEmitter');
import type EmitterSubscription from 'EmitterSubscription';
const Platform = require('Platform');
const React = require('React');
const StyleSheet = require('StyleSheet');
const _warningEmitter = new EventEmitter();
const _warningMap = new Map();
/**
* YellowBox renders warnings at the bottom of the app being developed.
*
* Warnings help guard against subtle yet significant issues that can impact the
* quality of the app. This "in your face" style of warning allows developers to
* notice and correct these issues as quickly as possible.
*
* By default, the warning box is enabled in `__DEV__`. Set the following flag
* to disable it (and call `console.warn` to update any rendered <YellowBox>):
*
* console.disableYellowBox = true;
* console.warn('YellowBox is disabled.');
*
* Warnings can be ignored programmatically by setting the array:
*
* console.ignoredYellowBox = ['Warning: ...'];
*
* Strings in `console.ignoredYellowBox` can be a prefix of the warning that
* should be ignored.
*/
if (__DEV__) {
const {error, warn} = console;
console.error = function() {
error.apply(console, arguments);
// Show yellow box for the `warning` module.
if (typeof arguments[0] === 'string' &&
arguments[0].startsWith('Warning: ')) {
updateWarningMap.apply(null, arguments);
}
};
console.warn = function() {
warn.apply(console, arguments);
updateWarningMap.apply(null, arguments);
};
}
/**
* Simple function for formatting strings.
*
* Replaces placeholders with values passed as extra arguments
*
* @param {string} format the base string
* @param ...args the values to insert
* @return {string} the replaced string
*/
function sprintf(format, ...args) {
var index = 0;
return format.replace(/%s/g, match => args[index++]);
}
function updateWarningMap(format, ...args): void {
const stringifySafe = require('stringifySafe');
format = String(format);
const argCount = (format.match(/%s/g) || []).length;
const warning = [
sprintf(format, ...args.slice(0, argCount)),
...args.slice(argCount).map(stringifySafe),
].join(' ');
const count = _warningMap.has(warning) ? _warningMap.get(warning) : 0;
_warningMap.set(warning, count + 1);
_warningEmitter.emit('warning', _warningMap);
}
function isWarningIgnored(warning: string): boolean {
return (
Array.isArray(console.ignoredYellowBox) &&
console.ignoredYellowBox.some(
ignorePrefix => warning.startsWith(ignorePrefix)
)
);
}
const WarningRow = ({count, warning, onPress}) => {
const Text = require('Text');
const TouchableHighlight = require('TouchableHighlight');
const View = require('View');
const countText = count > 1 ?
<Text style={styles.listRowCount}>{'(' + count + ') '}</Text> :
null;
return (
<View style={styles.listRow}>
<TouchableHighlight
activeOpacity={0.5}
onPress={onPress}
style={styles.listRowContent}
underlayColor="transparent">
<Text style={styles.listRowText} numberOfLines={2}>
{countText}
{warning}
</Text>
</TouchableHighlight>
</View>
);
};
const WarningInspector = ({
count,
warning,
onClose,
onDismiss,
onDismissAll,
}) => {
const ScrollView = require('ScrollView');
const Text = require('Text');
const TouchableHighlight = require('TouchableHighlight');
const View = require('View');
const countSentence =
'Warning encountered ' + count + ' time' + (count - 1 ? 's' : '') + '.';
return (
<TouchableHighlight
activeOpacity={0.95}
underlayColor={backgroundColor(0.8)}
onPress={onClose}
style={styles.inspector}>
<View style={styles.inspectorContent}>
<View style={styles.inspectorCount}>
<Text style={styles.inspectorCountText}>{countSentence}</Text>
</View>
<ScrollView style={styles.inspectorWarning}>
<Text style={styles.inspectorWarningText}>{warning}</Text>
</ScrollView>
<View style={styles.inspectorButtons}>
<TouchableHighlight
activeOpacity={0.5}
onPress={onDismiss}
style={styles.inspectorButton}
underlayColor="transparent">
<Text style={styles.inspectorButtonText}>
Dismiss
</Text>
</TouchableHighlight>
<TouchableHighlight
activeOpacity={0.5}
onPress={onDismissAll}
style={styles.inspectorButton}
underlayColor="transparent">
<Text style={styles.inspectorButtonText}>
Dismiss All
</Text>
</TouchableHighlight>
</View>
</View>
</TouchableHighlight>
);
};
class YellowBox extends React.Component {
state: {
inspecting: ?string;
warningMap: Map;
};
_listener: ?EmitterSubscription;
constructor(props: mixed, context: mixed) {
super(props, context);
this.state = {
inspecting: null,
warningMap: _warningMap,
};
this.dismissWarning = warning => {
const {inspecting, warningMap} = this.state;
if (warning) {
warningMap.delete(warning);
} else {
warningMap.clear();
}
this.setState({
inspecting: (warning && inspecting !== warning) ? inspecting : null,
warningMap,
});
};
}
componentDidMount() {
let scheduled = null;
this._listener = _warningEmitter.addListener('warning', warningMap => {
// Use `setImmediate` because warnings often happen during render, but
// state cannot be set while rendering.
scheduled = scheduled || setImmediate(() => {
scheduled = null;
this.setState({
warningMap,
});
});
});
}
componentWillUnmount() {
if (this._listener) {
this._listener.remove();
}
}
render() {
if (console.disableYellowBox || this.state.warningMap.size === 0) {
return null;
}
const ScrollView = require('ScrollView');
const View = require('View');
const inspecting = this.state.inspecting;
const inspector = inspecting !== null ?
<WarningInspector
count={this.state.warningMap.get(inspecting)}
warning={inspecting}
onClose={() => this.setState({inspecting: null})}
onDismiss={() => this.dismissWarning(inspecting)}
onDismissAll={() => this.dismissWarning(null)}
/> :
null;
const rows = [];
this.state.warningMap.forEach((count, warning) => {
if (!isWarningIgnored(warning)) {
rows.push(
<WarningRow
key={warning}
count={count}
warning={warning}
onPress={() => this.setState({inspecting: warning})}
onDismiss={() => this.dismissWarning(warning)}
/>
);
}
});
const listStyle = [
styles.list,
// Additional `0.4` so the 5th row can peek into view.
{height: Math.min(rows.length, 4.4) * (rowGutter + rowHeight)},
];
return (
<View style={inspector ? styles.fullScreen : listStyle}>
<ScrollView style={listStyle} scrollsToTop={false}>
{rows}
</ScrollView>
{inspector}
</View>
);
}
}
const backgroundColor = opacity => 'rgba(250, 186, 48, ' + opacity + ')';
const textColor = 'white';
const rowGutter = 1;
const rowHeight = 46;
var styles = StyleSheet.create({
fullScreen: {
backgroundColor: 'transparent',
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
},
inspector: {
backgroundColor: backgroundColor(0.95),
flex: 1,
},
inspectorContainer: {
flex: 1,
},
inspectorButtons: {
flexDirection: 'row',
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
},
inspectorButton: {
flex: 1,
padding: 22,
},
inspectorButtonText: {
color: textColor,
fontSize: 14,
opacity: 0.8,
textAlign: 'center',
},
inspectorContent: {
flex: 1,
paddingTop: 5,
},
inspectorCount: {
padding: 15,
paddingBottom: 0,
},
inspectorCountText: {
color: textColor,
fontSize: 14,
},
inspectorWarning: {
padding: 15,
position: 'absolute',
top: 39,
bottom: 60,
},
inspectorWarningText: {
color: textColor,
fontSize: 16,
fontWeight: '600',
},
list: {
backgroundColor: 'transparent',
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
},
listRow: {
position: 'relative',
backgroundColor: backgroundColor(0.95),
flex: 1,
height: rowHeight,
marginTop: rowGutter,
},
listRowContent: {
flex: 1,
},
listRowCount: {
color: 'rgba(255, 255, 255, 0.5)',
},
listRowText: {
color: textColor,
position: 'absolute',
left: 0,
top: Platform.OS === 'android' ? 5 : 7,
marginLeft: 15,
marginRight: 15,
},
});
module.exports = YellowBox;
@@ -1,139 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule renderApplication
*/
'use strict';
var Inspector = require('Inspector');
var Portal = require('Portal');
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var React = require('React');
var StyleSheet = require('StyleSheet');
var Subscribable = require('Subscribable');
var View = require('View');
var invariant = require('fbjs/lib/invariant');
var YellowBox = __DEV__ ? require('YellowBox') : null;
// require BackAndroid so it sets the default handler that exits the app if no listeners respond
require('BackAndroid');
var AppContainer = React.createClass({
mixins: [Subscribable.Mixin],
getInitialState: function() {
return {
enabled: __DEV__,
inspectorVisible: false,
rootNodeHandle: null,
rootImportanceForAccessibility: 'auto',
};
},
toggleElementInspector: function() {
this.setState({
inspectorVisible: !this.state.inspectorVisible,
rootNodeHandle: React.findNodeHandle(this.refs.main),
});
},
componentDidMount: function() {
this.addListenerOn(
RCTDeviceEventEmitter,
'toggleElementInspector',
this.toggleElementInspector
);
this._unmounted = false;
},
renderInspector: function() {
return this.state.inspectorVisible ?
<Inspector
rootTag={this.props.rootTag}
inspectedViewTag={this.state.rootNodeHandle}
/> :
null;
},
componentWillUnmount: function() {
this._unmounted = true;
},
setRootAccessibility: function(modalVisible) {
if (this._unmounted) {
return;
}
this.setState({
rootImportanceForAccessibility: modalVisible ? 'no-hide-descendants' : 'auto',
});
},
render: function() {
var RootComponent = this.props.rootComponent;
var appView =
<View
ref="main"
collapsable={!this.state.inspectorVisible}
style={styles.appContainer}>
<RootComponent
{...this.props.initialProps}
rootTag={this.props.rootTag}
importantForAccessibility={this.state.rootImportanceForAccessibility}/>
<Portal
onModalVisibilityChanged={this.setRootAccessibility}/>
</View>;
let yellowBox = null;
if (__DEV__) {
yellowBox = <YellowBox />;
}
return this.state.enabled ?
<View style={styles.appContainer}>
{appView}
{yellowBox}
{this.renderInspector()}
</View> :
appView;
}
});
function renderApplication<D, P, S>(
RootComponent: ReactClass<P>,
initialProps: P,
rootTag: any
) {
invariant(
rootTag,
'Expect to have a valid rootTag, instead got ', rootTag
);
React.render(
<AppContainer
rootComponent={RootComponent}
initialProps={initialProps}
rootTag={rootTag} />,
rootTag
);
}
var styles = StyleSheet.create({
// This is needed so the application covers the whole screen
// and therefore the contents of the Portal are not clipped.
appContainer: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
},
});
module.exports = renderApplication;
@@ -1,96 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule renderApplication
* @noflow
*/
'use strict';
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var React = require('React');
var StyleSheet = require('StyleSheet');
var Subscribable = require('Subscribable');
var View = require('View');
var invariant = require('fbjs/lib/invariant');
var Inspector = __DEV__ ? require('Inspector') : null;
var YellowBox = __DEV__ ? require('YellowBox') : null;
var AppContainer = React.createClass({
mixins: [Subscribable.Mixin],
getInitialState: function() {
return { inspector: null };
},
toggleElementInspector: function() {
var inspector = !__DEV__ || this.state.inspector
? null
: <Inspector
rootTag={this.props.rootTag}
inspectedViewTag={React.findNodeHandle(this.refs.main)}
/>;
this.setState({inspector});
},
componentDidMount: function() {
this.addListenerOn(
RCTDeviceEventEmitter,
'toggleElementInspector',
this.toggleElementInspector
);
},
render: function() {
let yellowBox = null;
if (__DEV__) {
yellowBox = <YellowBox />;
}
return (
<View style={styles.appContainer}>
<View collapsible={false} style={styles.appContainer} ref="main">
{this.props.children}
</View>
{yellowBox}
{this.state.inspector}
</View>
);
}
});
function renderApplication<D, P, S>(
RootComponent: ReactClass<P>,
initialProps: P,
rootTag: any
) {
invariant(
rootTag,
'Expect to have a valid rootTag, instead got ', rootTag
);
/* eslint-disable jsx-no-undef-with-namespace */
React.render(
<AppContainer rootTag={rootTag}>
<RootComponent
{...initialProps}
rootTag={rootTag}
/>
</AppContainer>,
rootTag
);
/* eslint-enable jsx-no-undef-with-namespace */
}
var styles = StyleSheet.create({
appContainer: {
flex: 1,
},
});
module.exports = renderApplication;
@@ -1,127 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule requireNativeComponent
* @flow
*/
'use strict';
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
var UIManager = require('UIManager');
var UnimplementedView = require('UnimplementedView');
var createReactNativeComponentClass = require('createReactNativeComponentClass');
var insetsDiffer = require('insetsDiffer');
var pointsDiffer = require('pointsDiffer');
var matricesDiffer = require('matricesDiffer');
var processColor = require('processColor');
var resolveAssetSource = require('resolveAssetSource');
var sizesDiffer = require('sizesDiffer');
var verifyPropTypes = require('verifyPropTypes');
var warning = require('fbjs/lib/warning');
/**
* Used to create React components that directly wrap native component
* implementations. Config information is extracted from data exported from the
* UIManager module. You should also wrap the native component in a
* hand-written component with full propTypes definitions and other
* documentation - pass the hand-written component in as `componentInterface` to
* verify all the native props are documented via `propTypes`.
*
* If some native props shouldn't be exposed in the wrapper interface, you can
* pass null for `componentInterface` and call `verifyPropTypes` directly
* with `nativePropsToIgnore`;
*
* Common types are lined up with the appropriate prop differs with
* `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`.
*/
import type { ComponentInterface } from 'verifyPropTypes';
function requireNativeComponent(
viewName: string,
componentInterface?: ?ComponentInterface,
extraConfig?: ?{nativeOnly?: Object},
): Function {
var viewConfig = UIManager[viewName];
if (!viewConfig || !viewConfig.NativeProps) {
warning(false, 'Native component for "%s" does not exist', viewName);
return UnimplementedView;
}
var nativeProps = {
...UIManager.RCTView.NativeProps,
...viewConfig.NativeProps,
};
viewConfig.uiViewClassName = viewName;
viewConfig.validAttributes = {};
viewConfig.propTypes = componentInterface && componentInterface.propTypes;
for (var key in nativeProps) {
var useAttribute = false;
var attribute = {};
var differ = TypeToDifferMap[nativeProps[key]];
if (differ) {
attribute.diff = differ;
useAttribute = true;
}
var processor = TypeToProcessorMap[nativeProps[key]];
if (processor) {
attribute.process = processor;
useAttribute = true;
}
viewConfig.validAttributes[key] = useAttribute ? attribute : true;
}
// Unfortunately, the current set up puts the style properties on the top
// level props object. We also need to add the nested form for API
// compatibility. This allows these props on both the top level and the
// nested style level. TODO: Move these to nested declarations on the
// native side.
viewConfig.validAttributes.style = ReactNativeStyleAttributes;
if (__DEV__) {
componentInterface && verifyPropTypes(
componentInterface,
viewConfig,
extraConfig && extraConfig.nativeOnly
);
}
return createReactNativeComponentClass(viewConfig);
}
var TypeToDifferMap = {
// iOS Types
CATransform3D: matricesDiffer,
CGPoint: pointsDiffer,
CGSize: sizesDiffer,
UIEdgeInsets: insetsDiffer,
// Android Types
// (not yet implemented)
};
function processColorArray(colors: []): [] {
return colors && colors.map(processColor);
}
var TypeToProcessorMap = {
// iOS Types
CGColor: processColor,
CGColorArray: processColorArray,
UIColor: processColor,
UIColorArray: processColorArray,
CGImage: resolveAssetSource,
UIImage: resolveAssetSource,
RCTImageSource: resolveAssetSource,
// Android Types
Color: processColor,
ColorArray: processColorArray,
};
module.exports = requireNativeComponent;
@@ -1,61 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule verifyPropTypes
* @flow
*/
'use strict';
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
export type ComponentInterface = ReactClass<any> | {
name?: string;
displayName?: string;
propTypes: Object;
};
function verifyPropTypes(
componentInterface: ComponentInterface,
viewConfig: Object,
nativePropsToIgnore?: ?Object
) {
if (!viewConfig) {
return; // This happens for UnimplementedView.
}
var componentName = componentInterface.name ||
componentInterface.displayName ||
'unknown';
if (!componentInterface.propTypes) {
throw new Error(
'`' + componentName + '` has no propTypes defined`'
);
}
var nativeProps = viewConfig.NativeProps;
for (var prop in nativeProps) {
if (!componentInterface.propTypes[prop] &&
!ReactNativeStyleAttributes[prop] &&
(!nativePropsToIgnore || !nativePropsToIgnore[prop])) {
var message;
if (componentInterface.propTypes.hasOwnProperty(prop)) {
message = '`' + componentName + '` has incorrectly defined propType for native prop `' +
viewConfig.uiViewClassName + '.' + prop + '` of native type `' + nativeProps[prop];
} else {
message = '`' + componentName + '` has no propType for native prop `' +
viewConfig.uiViewClassName + '.' + prop + '` of native type `' +
nativeProps[prop] + '`';
};
message += '\nIf you haven\'t changed this prop yourself, this usually means that ' +
'your versions of the native code and JavaScript code are out of sync. Updating both ' +
'should make this error go away.';
throw new Error(message);
}
}
}
module.exports = verifyPropTypes;
@@ -1,57 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule UIManagerStatTracker
* @flow
*/
'use strict';
var UIManager = require('UIManager');
var installed = false;
var UIManagerStatTracker = {
install: function() {
if (installed) {
return;
}
installed = true;
var statLogHandle;
var stats = {};
function printStats() {
console.log({UIManagerStatTracker: stats});
statLogHandle = null;
}
function incStat(key: string, increment: number) {
stats[key] = (stats[key] || 0) + increment;
if (!statLogHandle) {
statLogHandle = setImmediate(printStats);
}
}
var createViewOrig = UIManager.createView;
UIManager.createView = function(tag, className, rootTag, props) {
incStat('createView', 1);
incStat('setProp', Object.keys(props || []).length);
createViewOrig(tag, className, rootTag, props);
};
var updateViewOrig = UIManager.updateView;
UIManager.updateView = function(tag, className, props) {
incStat('updateView', 1);
incStat('setProp', Object.keys(props || []).length);
updateViewOrig(tag, className, props);
};
var manageChildrenOrig = UIManager.manageChildren;
UIManager.manageChildren = function(tag, moveFrom, moveTo, addTags, addIndices, remove) {
incStat('manageChildren', 1);
incStat('move', Object.keys(moveFrom || []).length);
incStat('remove', Object.keys(remove || []).length);
manageChildrenOrig(tag, moveFrom, moveTo, addTags, addIndices, remove);
};
},
};
module.exports = UIManagerStatTracker;
-35
View File
@@ -1,35 +0,0 @@
/**
* @generated SignedSource<<ec51291ea6059cf23faa74f8644d17b1>>
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !! This file is a check-in of a static_upstream project! !!
* !! !!
* !! You should not modify this file directly. Instead: !!
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
* !! the latest version from upstream. !!
* !! 2) Make your changes, test them, etc. !!
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
* !! static_upstream. !!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* @providesModule clamp
* @typechecks
*/
/**
* @param {number} value
* @param {number} min
* @param {number} max
* @return {number}
*/
function clamp(min, value, max) {
if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
}
module.exports = clamp;