mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 19:24:21 +00:00
89f5a13891
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
44 lines
1.2 KiB
JavaScript
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;
|