forked from knowbody/react-native-text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (23 loc) · 740 Bytes
/
index.js
File metadata and controls
28 lines (23 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from 'react';
import PropTypes from 'prop-types';
import { Dimensions, Text, StyleSheet } from 'react-native';
const { width, height } = Dimensions.get('window');
const flattenStyle = StyleSheet.flatten;
const realWidth = height > width ? width : height;
const ScalableText = ({ style, children, ...props }) => {
const fontSize = flattenStyle(style).fontSize || 14;
const scaledFontSize = Math.round(fontSize * realWidth / 375);
return (
<Text style={[style, { fontSize: scaledFontSize }]} {...props}>
{children}
</Text>
);
};
ScalableText.propTypes = {
style: Text.propTypes.style,
children: PropTypes.node.isRequired
};
ScalableText.defaultProps = {
style: {}
};
export default ScalableText;