Skip to content

Commit 6df4bae

Browse files
author
Igor Canedo
committed
support to astral symbols
1 parent 2df1673 commit 6df4bae

File tree

9 files changed

+310
-43
lines changed

9 files changed

+310
-43
lines changed

flow-typed/npm/stringz_vx.x.x.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// flow-typed signature: 17908e8cb7dcac8f4cfe9378780b0286
2+
// flow-typed version: <<STUB>>/stringz_v0.2.2/flow_v0.53.1
3+
4+
/**
5+
* This is an autogenerated libdef stub for:
6+
*
7+
* 'stringz'
8+
*
9+
* Fill this stub out by replacing all the `any` types.
10+
*
11+
* Once filled out, we encourage you to share your work with the
12+
* community by sending a pull request to:
13+
* https://github.com/flowtype/flow-typed
14+
*/
15+
16+
declare module 'stringz' {
17+
declare module.exports: any;
18+
}
19+
20+
/**
21+
* We include stubs for each file inside this npm package in case you need to
22+
* require those files directly. Feel free to delete any files that aren't
23+
* needed.
24+
*/
25+
declare module 'stringz/coverage/lcov-report/prettify' {
26+
declare module.exports: any;
27+
}
28+
29+
declare module 'stringz/coverage/lcov-report/sorter' {
30+
declare module.exports: any;
31+
}
32+
33+
declare module 'stringz/dist/index' {
34+
declare module.exports: any;
35+
}
36+
37+
declare module 'stringz/dist/length' {
38+
declare module.exports: any;
39+
}
40+
41+
declare module 'stringz/dist/string' {
42+
declare module.exports: any;
43+
}
44+
45+
// Filename aliases
46+
declare module 'stringz/coverage/lcov-report/prettify.js' {
47+
declare module.exports: $Exports<'stringz/coverage/lcov-report/prettify'>;
48+
}
49+
declare module 'stringz/coverage/lcov-report/sorter.js' {
50+
declare module.exports: $Exports<'stringz/coverage/lcov-report/sorter'>;
51+
}
52+
declare module 'stringz/dist/index.js' {
53+
declare module.exports: $Exports<'stringz/dist/index'>;
54+
}
55+
declare module 'stringz/dist/length.js' {
56+
declare module.exports: $Exports<'stringz/dist/length'>;
57+
}
58+
declare module 'stringz/dist/string.js' {
59+
declare module.exports: $Exports<'stringz/dist/string'>;
60+
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
"react": "^16.0.0-alpha.12",
2424
"react-native": "^0.47.2"
2525
},
26+
"dependencies": {
27+
"stringz": "0.2.2"
28+
},
2629
"devDependencies": {
2730
"babel-eslint": "^7.2.3",
2831
"babel-jest": "^20.0.3",
32+
"babel-plugin-add-module-exports": "0.2.1",
33+
"babel-preset-es2015": "^6.24.1",
2934
"babel-preset-react-native": "^2.1.0",
3035
"coveralls": "^2.12.0",
3136
"eslint": "^4.4.1",

sample/__tests__/loadAttributes.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ it('have correct length with inlineStyles and text', () => {
3737
expect(result).toHaveLength(3);
3838
});
3939

40+
it('have correct length with inlineStyles and text width astral symbols', () => {
41+
const params = {
42+
text: 'Iñtërnâtiônàlizætiøn☃💩 Etiama nisi augue ultricie qa magna',
43+
inlineStyles: [
44+
{
45+
offset: 4,
46+
length: 35,
47+
style: 'BOLD',
48+
},
49+
],
50+
entityMap: {},
51+
entityRanges: [],
52+
};
53+
const result = loadAttributes(params);
54+
expect(result).toHaveLength(2);
55+
});
56+
4057
it('have correct length with multiple inlineStyles and text', () => {
4158
const params = {
4259
text: 'Hello World Hello World Hello World',

sample/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
},
1313
"dependencies": {
1414
"react": "16.0.0-alpha.12",
15-
"react-native": "0.47.2"
15+
"react-native": "0.47.2",
16+
"stringz": "0.2.2"
1617
},
1718
"devDependencies": {
1819
"babel-jest": "^20.0.3",
1920
"babel-preset-react-native": "^2.1.0",
21+
"babel-preset-es2015": "^6.24.1",
22+
"babel-plugin-add-module-exports": "0.2.1",
2023
"jest": "^20.0.4",
2124
"react-test-renderer": "16.0.0-alpha.12",
2225
"sync-files": "1.0.3"

sample/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const styles = StyleSheet.create({
2222
container: {
2323
flex: 1,
2424
paddingHorizontal: 16,
25+
marginTop: 32,
2526
backgroundColor: '#f4f4f4',
2627
},
2728
});

sample/src/resourceMock.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@
3434
"entityRanges": [],
3535
"data": {}
3636
},
37+
{
38+
"key": "3lkq2",
39+
"text": "Ma 🎤Iñtërnâtiônàlizætiøn☃💩 Etiama nia",
40+
"type": "unstyled",
41+
"depth": 0,
42+
"inlineStyleRanges": [],
43+
"entityRanges": [
44+
{
45+
"offset": 2,
46+
"length": 35,
47+
"key": 0
48+
}
49+
],
50+
"data": {}
51+
},
52+
{
53+
"key": "7noje",
54+
"text": "🎤 Etiama augue 'ultricie ultric'",
55+
"type": "unstyled",
56+
"depth": 0,
57+
"inlineStyleRanges": [],
58+
"entityRanges": [
59+
{
60+
"offset": 1,
61+
"length": 31,
62+
"key": 0
63+
}
64+
],
65+
"data": {}
66+
},
3767
{
3868
"key": "5r864123",
3969
"text": "Etiam ultricies nisi vel augue.",

sample/yarn.lock

Lines changed: 93 additions & 19 deletions
Large diffs are not rendered by default.

src/loadAttributes.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// @flow
88

9+
import { substring, length } from 'stringz';
910
import React from 'react';
1011
import {
1112
Text,
@@ -42,6 +43,7 @@ const loadAttributes = (params: ParamsType): any => {
4243
entityMap,
4344
navigate,
4445
} = params;
46+
4547
const defaultNavigationFn = (url: string) => { Linking.openURL(url); };
4648
const navigateFunction = navigate || defaultNavigationFn;
4749
const elementList = [];
@@ -52,14 +54,15 @@ const loadAttributes = (params: ParamsType): any => {
5254
const attrs = flatAttributesList(attributes);
5355

5456
if (attrs[0].offset > 0) {
55-
elementList.push(<Text key={generateKey()}>{text.substring(0, attrs[0].offset)}</Text>);
57+
elementList.push(
58+
<Text key={generateKey()}>{substring(text, 0, attrs[0].offset)}</Text>);
5659
}
5760

5861
attrs.forEach((item: Object, index: number) => {
5962
if (index > 0) {
6063
const previousItem = attrs[index - 1];
6164
const offset = previousItem.offset + previousItem.length;
62-
const subText = text.substring(offset, item.offset);
65+
const subText = substring(text, offset, item.offset);
6366

6467
if (subText.length) {
6568
elementList.push(<Text key={generateKey()}>{subText}</Text>);
@@ -70,7 +73,7 @@ const loadAttributes = (params: ParamsType): any => {
7073
const itemData = Object.assign({}, {
7174
key: generateKey(),
7275
type: itemType,
73-
text: text.substring(item.offset, item.offset + item.length),
76+
text: substring(text, item.offset, item.offset + item.length),
7477
customStyles,
7578
});
7679

@@ -84,7 +87,7 @@ const loadAttributes = (params: ParamsType): any => {
8487

8588
const lastItem = attrs[attrs.length - 1];
8689
const offset = lastItem.offset + lastItem.length;
87-
const subText = text.substring(offset, text.length);
90+
const subText = substring(text, offset, length(text));
8891

8992
if (subText.length) {
9093
elementList.push(<Text key={generateKey()}>{subText}</Text>);

0 commit comments

Comments
 (0)