You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,12 @@
2
2
3
3
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
5
-
## [Unreleased]
5
+
## [2.0.2] - 2018-08-31
6
+
### Changed
7
+
- iOS: Give `flatHeights` better performace by avoiding multiple creation of NSTextStorage.
6
8
7
9
### Fixed
10
+
- Closes #5: Inconsistency in flatHeights between Android and iOS.
8
11
- Some error in the README and include note about unlink the previous version.
Copy file name to clipboardExpand all lines: README.md
+34-21Lines changed: 34 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,14 +31,14 @@ Both, width and height, are practically the same as those received from the `onL
31
31
32
32
In addition, the library includes functions to obtain information about the fonts visible to the App.
33
33
34
-
rnTextSize is WIP, but if it has helped you, please support my work with a star :star2: or [buy me a coffee](https://www.buymeacoffee.com/aMarCruz).
34
+
rnTextSize is WIP, but if it has helped you, please support my work with a star :star2: or [buy me a coffee][bmc-url].
35
35
36
36
---
37
37
**IMPORTANT:**
38
38
39
39
**rnTextSize (react-native-text-size) v2.0 is a complete refactoring, before using it, please unlink the previous version.**
40
40
41
-
**If `react-native unlink` fails, please reverse the changes described in [Manual Installation](https://github.com/aMarCruz/react-native-text-size/wiki/Manual-Installation).**
41
+
**If `react-native unlink` fails, please reverse the changes described in [Manual Installation][2].**
42
42
43
43
---
44
44
@@ -47,7 +47,7 @@ rnTextSize is WIP, but if it has helped you, please support my work with a star
47
47
- React Native v0.52.0 or later
48
48
- Targets Android API 16 and iOS 9.0
49
49
50
-
The [sample App](https://github.com/aMarCruz/rn-text-size-sample-app) uses RN v0.52.0, the minimum supported version but, to take advantage of features such as `letterSpacing` and better support for the most modern devices, use RN v0.55 or above.
50
+
The [sample App][1] uses RN v0.52.0, the minimum supported version but, to take advantage of features such as `letterSpacing` and better support for the most modern devices, use RN v0.55 or above.
51
51
52
52
## Installation
53
53
@@ -58,7 +58,7 @@ $ react-native link react-native-text-size
58
58
59
59
If you are using Gradle 4 or later, don't forget to change the `compile` directive to `implementation` in the dependencies block of the android/app/build.gradle file.
60
60
61
-
See [Manual Installation](https://github.com/aMarCruz/react-native-text-size/wiki/Manual-Installation) on the Wiki as an alternative if you have problems with automatic installation.
61
+
See [Manual Installation][2] on the Wiki as an alternative if you have problems with automatic installation.
62
62
63
63
## API
64
64
@@ -80,7 +80,7 @@ See [Manual Installation](https://github.com/aMarCruz/react-native-text-size/wik
This function measures the text as RN does and its result is consistent\* with that of `Text`'s onLayout event. It take a subset of the properties used by [`<Text>`](https://facebook.github.io/react-native/docs/text#props) to describe the font and other options to use.
83
+
This function measures the text as RN does and its result is consistent\* with that of `Text`'s onLayout event. It take a subset of the properties used by [`<Text>`][3] to describe the font and other options to use.
84
84
85
85
If you provide the `width`, the measurement will apply automatic wrapping in addition to the explicit line breaks.
text | string | (none) | This is the only required parameter and may include _emojis_ or be empty, but it can not be `null`. If this is an empty string the resulting `width` will be zero.
100
100
width | number | Infinity | Restrict the width. The resulting height will vary depending on the automatic flow of the text.
101
-
usePreciseWidth | boolean | false | If `true`, request an exact `width` and the value of `lastLineWidth` (iOS always returns the exact width).<br>You can see the effect of this flag in the [sample App](https://github.com/aMarCruz/rn-text-size-sample-app).
101
+
usePreciseWidth | boolean | false | If `true`, request an exact `width` and the value of `lastLineWidth` (iOS always returns the exact width).<br>You can see the effect of this flag in the [sample App][1].
102
102
fontFamily | string | OS dependent | The default is the same applied by React Native: Roboto in Android, San Francisco in iOS.<br>**Note:** Device manufacturer or custom ROM can change the default font.
103
103
fontWeight | string | 'normal' | On android, numeric ranges has no granularity and '500' to '900' becomes 'bold', but you can use fonts of specific weights, like "sans-serif-medium".
104
104
fontSize | number | 14 | The default value comes from RN.
@@ -109,15 +109,15 @@ letterSpacing | number | (none) | Additional spacing between characters (
109
109
includeFontPadding | boolean | true | Include additional top and bottom padding, to avoid clipping certain characters.<br>_Android only_
110
110
textBreakStrategy | string | 'highQuality' | One of 'simple', 'balanced', or 'highQuality'.<br>_Android only, with API 23+_
111
111
112
-
The [sample App](https://github.com/aMarCruz/rn-text-size-sample-app) shows interactively the effect of these parameters on the screen.
112
+
The [sample App][1] shows interactively the effect of these parameters on the screen.
113
113
114
114
**TSMeasureResult**
115
115
116
116
`measure` returns a Promise that resolves to a plain JS object with this properties:
117
117
118
118
Property | Type | Notes
119
119
--------- | ------ | ------
120
-
width | number | Total used width. It may be less or equal to the given width.On Android this value may vary depending on the `usePreciseWidth` flag.
120
+
width | number | Total used width. It may be less or equal to the given width.<br>On Android this value may vary depending on the `usePreciseWidth` flag.
121
121
height | number | Total height, including top and bottom padding if `includingFontPadding` was set (the default).
122
122
lastLineWidth | number | Width of the last line, without trailing blanks.<br>__Note:__ If `usePreciseWidth` is `false` (the default), this field is undefined.
123
123
lineCount | number | Number of lines, taking into account hard and automatic line breaks.
@@ -221,7 +221,7 @@ letterSpacing | number | (none)
221
221
includeFontPadding | boolean | true
222
222
textBreakStrategy | string | 'highQuality'
223
223
224
-
The result is a Promise that is resolves with an array with the height of each block (_SP_), in the same order in which the blocks were received.
224
+
The result is a Promise that resolves to an array with the height of each block (_SP_), in the same order in which the blocks were received.
225
225
226
226
Unlike measure, `null` elements returns 0 without generating error, and empty strings returns the same height that RN assigns to empty `<Text>` components (the difference of the result between `null` and empty is intentional).
This is a wrapper for the iOS [`UIFont.preferredFontForTextStyle`](https://developer.apple.com/documentation/uikit/uifont/1619030-preferredfontfortextstyle) method and the current Android [Material Design Type Scale](https://material.io/design/typography/#type-scale) styles.
237
+
This is a wrapper for the iOS [`UIFont.preferredFontForTextStyle`][4] method and the current Android [Material Design Type Scale][5] styles.
238
238
239
239
The result is a Promise that resolves to a JS object whose keys depend on the OS, but its values are in turn objects fully compatible with those used in the RN styles, so it can be used to stylize `<Text>` or `<TextInput>` components:
240
240
@@ -249,7 +249,7 @@ fontWeight | TSFontWeight | Only if 'bold', undefined if the weight is 'norma
249
249
fontVariant | TSFontVariant[] or null | _iOS only_. Currently, no style includes this property.
250
250
letterSpacing | number | Omitted if running on Android with RN lower than 0.55
251
251
252
-
To know the key names, please see [Keys from specsForTextStyles](https://github.com/aMarCruz/react-native-text-size/wiki/Keys-from-specsForTextStyles) the Wiki.
252
+
To know the key names, please see [Keys from specsForTextStyles][6] the Wiki.
253
253
254
254
I have not tried to normalize these keys since, with the exception of 2 or 3, they have a different interpretation in each OS. You will know how to use them to create custom styles according to your needs.
255
255
@@ -264,7 +264,7 @@ Returns the characteristics of the font obtained from the given specifications.
264
264
265
265
**TSFontSpecs**
266
266
267
-
This parameter is a subset of [`TSMeasureParams`](#tsmeasureparams), so the details are omitted here.
267
+
This parameter is a subset of [`TSMeasureParams`](#incorrent-height-ios), so the details are omitted here.
268
268
269
269
Property | Type | Default
270
270
---------- | ------ | -------
@@ -279,7 +279,7 @@ letterSpacing | number | 0
279
279
280
280
<aname="tsfontinfo"></a> **TSFontInfo**
281
281
282
-
The result is a Promise that resolves to a JS object with info for the given font and size, units in [_SP_](https://developer.android.com/guide/topics/resources/more-resources#Dimension) in Android or points in iOS, using floating point numbers where applicable\*.
282
+
The result is a Promise that resolves to a JS object with info for the given font and size, units in [_SP_][7] in Android or points in iOS, using floating point numbers where applicable\*.
283
283
284
284
Property | Type | Details
285
285
----------- | ------ | --------
@@ -303,9 +303,9 @@ _hash | number | Hash code, maybe useful for debugging.
303
303
304
304
See more in:
305
305
306
-
[Understanding typography](https://material.io/design/typography/understanding-typography.html#type-properties) at the Google Material Design site.
306
+
[Understanding typography][8] at the Google Material Design site.
307
307
308
-
[About Text Handling in iOS](https://developer.apple.com/library/archive/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009542.) for iOS.
Returns a Promise for an array of font family names available on the system.
324
324
325
-
On iOS, this uses the [`UIFont.familyNames`](https://developer.apple.com/documentation/uikit/uifont/1619040-familynames?language=objc) method of the UIKit.
325
+
On iOS, this uses the [`UIFont.familyNames`][10] method of the UIKit.
326
326
327
-
On Android the result is hard-coded for the system fonts and complemented dynamically with the custom fonts, if any.
327
+
On Android the result is hard-coded for the system fonts and complemented dynamically with the fonts installed by your app, if any.
328
328
329
-
See [About Android Fonts](https://github.com/aMarCruz/react-native-text-size/wiki/About-Android-Fonts) and [Custom Fonts](https://github.com/aMarCruz/react-native-text-size/wiki/Custom-Fonts) in the Wiki to know more about this list.
329
+
See [About Android Fonts][11] and [Custom Fonts][12] in the Wiki to know more about this list.
330
330
331
331
332
332
## fontNamesForFamilyName
@@ -350,7 +350,7 @@ On iOS, RN takes into account the absolute position on the screen to calculate t
350
350
351
351
#### letterSpacing not scaling (iOS)
352
352
353
-
RN does not support the [Dynamic Type Sizes](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography#dynamic-type-sizes), but does an excellent job imitating this feature through `allowFontScaling` ...except for `letterSpacing` that is not scaled.
353
+
RN does not support the [Dynamic Type Sizes][13], but does an excellent job imitating this feature through `allowFontScaling` ...except for `letterSpacing` that is not scaled.
354
354
355
355
I hope that a future version of RN solves this issue.
356
356
@@ -373,7 +373,6 @@ Nested `<Text>` components (or with images inside) can be rasterized with dimens
373
373
-[ ] And a lot of more things.
374
374
-[ ] Ahh a... lot of money, of course. I need a Mac 😆 so...
375
375
376
-
377
376
## Support my Work
378
377
379
378
I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time and effort so, if you like my work, please consider...
@@ -387,7 +386,7 @@ Thanks for your support!
387
386
388
387
## License
389
388
390
-
The [BSD 2-Clause](LICENCE) "Simplified" License.
389
+
The [BSD 2-Clause](LICENSE) "Simplified" License.
391
390
392
391
Copyright (c) 2018, Alberto Martínez. All rights reserved.
393
392
@@ -397,3 +396,17 @@ Copyright (c) 2018, Alberto Martínez. All rights reserved.
0 commit comments