Skip to content

Commit 266b84c

Browse files
committed
约束Text and TextInput
1 parent 0780eb0 commit 266b84c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/page/Login/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LoginScreen extends Component<Props, State> {
3434
/>
3535
);
3636
}
37+
3738
onChangeText = text => {
3839
console.log(text);
3940
};

src/page/Root.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Image,
1111
View,
1212
Text,
13+
TextInput,
1314
StyleSheet,
1415
StatusBar,
1516
ActivityIndicator,
@@ -26,13 +27,30 @@ import { ListRow, Toast } from 'teaset';
2627
import ToastView from '../equipment/ToastUtil';
2728
import PopupDialog from '../modules/PopupDialog';
2829
import MaskedView from '../modules/MaskedView';
29-
let oldRender = Text.prototype.render;
30-
Text.prototype.render = function(...args) {
31-
let origin = oldRender.call(this, ...args);
32-
return React.cloneElement(origin, {
33-
style: [origin.props.style, { fontFamily: 'PingFangTC-Medium' }]
34-
});
30+
let components = [Text, TextInput];
31+
const customProps = {
32+
style: {
33+
fontFamily: 'PingFangTC-Medium'
34+
},
35+
allowFontScaling: false
3536
};
37+
components.map((item, index) => {
38+
const TextRender = item.prototype.render;
39+
const initialDefaultProps = item.prototype.constructor.defaultProps;
40+
item.prototype.constructor.defaultProps = {
41+
...initialDefaultProps,
42+
...customProps
43+
};
44+
item.prototype.render = function render() {
45+
let oldProps = this.props;
46+
this.props = { ...this.props, ...customProps, style: [this.props.style] };
47+
try {
48+
return TextRender.apply(this, arguments);
49+
} finally {
50+
this.props = oldProps;
51+
}
52+
};
53+
});
3654
const customAnimationConfig = {
3755
duration: 400,
3856
create: {

0 commit comments

Comments
 (0)