Skip to content

Commit 61ae71b

Browse files
committed
First commit
0 parents  commit 61ae71b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+7695
-0
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// avoid interference of any eslint config in parent directory
2+
module.exports = {
3+
root: true
4+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
# OSX
3+
#
4+
.DS_Store
5+
6+
# node.js
7+
#
8+
node_modules/
9+
npm-debug.log
10+
yarn-error.log
11+
12+
13+
# Xcode
14+
#
15+
build/
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
xcuserdata
25+
*.xccheckout
26+
*.moved-aside
27+
DerivedData
28+
*.hmap
29+
*.ipa
30+
*.xcuserstate
31+
project.xcworkspace
32+
33+
34+
# Android/IntelliJ
35+
#
36+
build/
37+
.idea
38+
.gradle
39+
local.properties
40+
*.iml
41+
42+
# BUCK
43+
buck-out/
44+
\.buckd/
45+
*.keystore
46+

.npmignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# OSX
3+
#
4+
.DS_Store
5+
6+
# node.js
7+
#
8+
node_modules/
9+
npm-debug.log
10+
yarn-error.log
11+
example/
12+
13+
# Xcode
14+
#
15+
build/
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
xcuserdata
25+
*.xccheckout
26+
*.moved-aside
27+
DerivedData
28+
*.hmap
29+
*.ipa
30+
*.xcuserstate
31+
project.xcworkspace
32+
33+
34+
# Android/IntelliJ
35+
#
36+
build/
37+
.idea
38+
.gradle
39+
local.properties
40+
*.iml
41+
42+
# BUCK
43+
buck-out/
44+
\.buckd/
45+
*.keystore

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Alberto Martínez
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# React Native Text Size
2+
3+
Measure text width and height without laying it out.
4+
5+
[![npm Version][npm-image]][npm-url]
6+
[![License][license-image]][license-url]
7+
8+
## Installation
9+
10+
### Automatic installation
11+
12+
`$ yarn add react-native-text-size`
13+
14+
`$ react-native link react-native-text-size`
15+
16+
### Manual installation
17+
18+
#### iOS
19+
20+
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
21+
2. Go to `node_modules``react-native-text-size` and add `RNMeasureText.xcodeproj`
22+
3. In XCode, in the project navigator, select your project. Add `libRNMeasureText.a` to your project's `Build Phases``Link Binary With Libraries`
23+
4. Run your project (`Cmd+R`)<
24+
25+
#### Android
26+
27+
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
28+
- Add `import io.github.amarcruz.RNMeasureTextPackage;` to the imports at the top of the file
29+
- Add `new RNMeasureTextPackage()` to the list returned by the `getPackages()` method
30+
2. Append the following lines to `android/settings.gradle`:
31+
```
32+
include ':react-native-text-size'
33+
project(':react-native-text-size').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-text-size/android')
34+
```
35+
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
36+
```
37+
compile project(':react-native-text-size')
38+
```
39+
40+
## Syntax
41+
42+
```js
43+
TextSize.measure({
44+
text: string,
45+
fontSize: number,
46+
fontFamily?: string,
47+
width?: number
48+
}) => {
49+
width: number,
50+
height: number,
51+
lineCount: number,
52+
lastLineMax: number
53+
}
54+
```
55+
56+
## Example
57+
58+
```js
59+
import MeasureText from 'react-native-text-size';
60+
61+
const text = 'This is an example';
62+
const width = 100;
63+
const fontSize = 16;
64+
const fontFamily = 'Roboto';
65+
66+
class Test extends Component {
67+
state = {
68+
width: 0,
69+
height: 0,
70+
}
71+
async componentDidMount() {
72+
const size = await MeasureText.measure({
73+
text, // texts to measure
74+
width, // container width
75+
fontSize,
76+
fontFamily
77+
});
78+
this.setState({
79+
width: size.width,
80+
height: size.height
81+
});
82+
}
83+
render() {
84+
const { width, height } = this.state;
85+
return (
86+
<View>
87+
<Text style={{ width, height, fontSize, fontFamily }}>
88+
{text}
89+
</Text>
90+
</View>
91+
);
92+
}
93+
}
94+
```
95+
96+
## License
97+
98+
The [MIT License](LICENCE) (MIT)
99+
100+
Copyright (c) 2017 Alberto Martínez (https://github.com/aMarCruz)
101+
102+
[npm-image]: https://img.shields.io/npm/v/react-native-text-size.svg
103+
[npm-url]: https://www.npmjs.com/package/react-native-text-size
104+
[license-image]: https://img.shields.io/npm/l/express.svg
105+
[license-url]: https://github.com/aMarCruz/jscc-brunch/blob/master/LICENSE

android/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
buildscript {
3+
repositories {
4+
jcenter()
5+
}
6+
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:1.3.1'
9+
}
10+
}
11+
12+
apply plugin: 'com.android.library'
13+
14+
android {
15+
compileSdkVersion 23
16+
buildToolsVersion "23.0.1"
17+
18+
defaultConfig {
19+
minSdkVersion 16
20+
targetSdkVersion 22
21+
versionCode 1
22+
versionName "1.0"
23+
}
24+
lintOptions {
25+
abortOnError false
26+
}
27+
}
28+
29+
repositories {
30+
mavenCentral()
31+
}
32+
33+
dependencies {
34+
compile 'com.facebook.react:react-native:+'
35+
}

android/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="io.github.amarcruz">
4+
5+
</manifest>

0 commit comments

Comments
 (0)