Files
react-native-web/src/modules/applyLayout/index.js
T
Nicolas Gallagher 89f5a13891 [change] TextInput uses DOM elements
This patch changes TextInput to use DOM inputs directly, rather than
trying to reimplement 'placeholder'. Removes support for
'placeholderTextColor'.

Fix #54
Fix #224
Fix #229
Fix #235
Fix #253
2016-11-21 16:52:40 -08:00

44 lines
1.2 KiB
JavaScript

/**
* Copyright (c) 2016-present, Nicolas Gallagher.
* All rights reserved.
*
* @flow
*/
import emptyFunction from 'fbjs/lib/emptyFunction';
const applyLayout = (Component) => {
const componentDidMount = Component.prototype.componentDidMount || emptyFunction;
const componentDidUpdate = Component.prototype.componentDidUpdate || emptyFunction;
Component.prototype.componentDidMount = function () {
componentDidMount.call(this);
this._layoutState = {};
this._handleLayout();
};
Component.prototype.componentDidUpdate = function () {
componentDidUpdate.call(this);
this._handleLayout();
};
Component.prototype._handleLayout = function () {
const layout = this._layoutState;
const { onLayout } = this.props;
if (onLayout) {
this.measure((x, y, width, height) => {
if (layout.x !== x || layout.y !== y || layout.width !== width || layout.height !== height) {
const nextLayout = { x, y, width, height };
const nativeEvent = { layout: nextLayout };
onLayout({ nativeEvent });
this._layoutState = nextLayout;
}
});
}
};
return Component;
};
module.exports = applyLayout;