Skip to content

Commit

Permalink
Merge pull request #22 from fram-x/release/1.0.0
Browse files Browse the repository at this point in the history
Release/1.0.0
  • Loading branch information
bjornegil committed Jun 9, 2019
2 parents 1eb5c0f + ede4993 commit 61c6661
Show file tree
Hide file tree
Showing 34 changed files with 2,539 additions and 2,186 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

3 changes: 1 addition & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true
Expand Down Expand Up @@ -67,4 +66,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.81.0
^0.92.0
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"eslint.enable": true,
"eslint.autoFixOnSave": true,
// "eslint.enable": true,
// "eslint.autoFixOnSave": true,
// For flow
"flow.runOnAllFiles": true,
"flow.useNPMPackagedFlow": true,
Expand Down
44 changes: 29 additions & 15 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,54 @@ export default class App extends Component<Props> {
return (
<View style={styles.container}>
<StyledText
text="Welcome to <b>React <u>Native</u> <demo><i>Styled</i> Text</demo></b> demo!"
style={styles.welcome}
textStyles={textStyles}
/>
>
{"Welcome to <b>React <u>Native</u> <demo><i>Styled</i> Text</demo></b> demo!"}
</StyledText>
<StyledText
text="Run <code>yarn add react-native-styled-text</code> to install"
style={styles.instruction}
textStyles={textStyles}
/>
>
{"Run <code>yarn add react-native-styled-text</code> to install"}
</StyledText>
<View style={styles.jsxContainer}>
<StyledText
text={'<ltgt>&lt;</ltgt><comp>StyledText</comp>'}
style={styles.jsx}
textStyles={jsxStyles}
/>
>
{'<ltgt>&lt;</ltgt><comp>StyledText</comp>'}
</StyledText>
<StyledText
text={'text<eq>=</eq><string>"Ha&lt;i&gt;pp&lt;/i&gt;y &lt;b&gt;Styling&lt;/b&gt;!"'}
style={[styles.jsx, styles.jsxProp]}
textStyles={jsxStyles}
/>
>
{"style<eq>=</eq><brace>{</brace>styles.header<brace>}</brace>"}
</StyledText>
<StyledText
style={styles.jsx}
textStyles={jsxStyles}
>
{'<ltgt>></ltgt>'}
</StyledText>
<StyledText
text={"style<eq>=</eq><brace>{</brace>styles.header<brace>}</brace>"}
style={[styles.jsx, styles.jsxProp]}
textStyles={jsxStyles}
/>
>
{'<brace>{</brace><string>"Ha&lt;i&gt;pp&lt;/i&gt;y &lt;b&gt;Styling&lt;/b&gt;!"<brace>}</brace>'}
</StyledText>
<StyledText
text="<ltgt>/></ltgt>"
style={styles.jsx}
textStyles={jsxStyles}
/>
>
{'<ltgt>&lt;\/</ltgt><comp>StyledText</comp><ltgt>></ltgt>'}
</StyledText>
</View>
<StyledText
text="Ha<i>pp</i>y <b>Styling</b>!"
style={styles.header}
/>
>
{"Ha<i>pp</i>y <b>Styling</b>!"}
</StyledText>
</View>
);
}
Expand Down Expand Up @@ -94,9 +107,10 @@ const styles = StyleSheet.create({
jsx: {
textAlign: 'left',
paddingLeft: 10,
paddingVertical: 4,
paddingVertical: 0,
fontWeight: '500',
fontSize: 12,

fontFamily: 'courier',
},
jsxProp: {
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The purpose of this library is to support easy rendering of mixed text styles.
<img src="https://github.com/fram-x/react-native-styled-text/raw/develop/docs/example-ios.png" width="400" />
<img src="https://github.com/fram-x/react-native-styled-text/raw/develop/docs/example-android.png" width="400" />

The library implements a `StyledText` component taking an HTML-like text and a styles object as input properties.
The library implements a `StyledText` component taking an HTML-like string in the `children` property and an optional text styles property.

## Installation
To install the library into your project, run yarn or npm:
Expand Down Expand Up @@ -39,9 +39,10 @@ import StyledText from 'react-native-styled-text';

...
<StyledText
text="Ha<i>pp</i>y <b>Styling</b>!"
style={styles.header}
/>
>
{"Ha<i>pp</i>y <b>Styling</b>!"}
</StyledText>
...

const styles = StyleSheet.create({
Expand Down Expand Up @@ -70,10 +71,11 @@ import StyledText from 'react-native-styled-text';

...
<StyledText
text="Welcome to <b><u>React Native</u> <demo><i>Styled</i> Text</demo></b> demo!"
style={styles.welcome}
textStyles={textStyles}
/>
>
{"Welcome to <b><u>React Native</u> <demo><i>Styled</i> Text</demo></b> demo!"}
</StyledText>
...

const styles = StyleSheet.create({
Expand Down Expand Up @@ -102,15 +104,16 @@ Renders as

## How it works

Internally, the `render` function of `StyledText` parses the value of the `text` property and returns a nested structure of React Native [`Text`](https://facebook.github.io/react-native/docs/text) components.
Internally, the `render` function of `StyledText` parses the value of the `children` property, which must be a string, and returns a nested structure of React Native [`Text`](https://facebook.github.io/react-native/docs/text) components.

From the example above:

```javascript
<StyledText
text="Ha<i>pp</i>y <b>Styling</b>!"
style={styles.header}
/>
>
{"Ha<i>pp</i>y <b>Styling</b>!"}
</StyledText>
```
would be transformed to:

Expand All @@ -125,11 +128,12 @@ So `StyledText` just provides a more compact, readable and flexible coding of ne


## API
In addition to the React Native `Text` properties, `StyledText` supports the following properties:

In addition to the React Native `Text` properties, `StyledText` supports the following properties, with a restriction on the `children` proerty:

| Name | Description |
| ---- | ----------- |
| text | String with style tags for mixed styling of the text. Each style tag must match one of the styles provided in textStyles or one of the default styles, see below. |
| children | String with style tags for mixed styling of the text. Each style tag must match one of the styles provided in textStyles or one of the default styles, see below. (Optional) |
| textStyles | Object (e.g. `StyleSheet`) containing definition of the styles used in the provided text. (Optional) |

The following default styles are defined:
Expand Down
14 changes: 14 additions & 0 deletions __tests__/App-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
});
18 changes: 4 additions & 14 deletions android/app/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@
# - `buck install -r android/app` - compile, install and run application
#

load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")

lib_deps = []

for jarfile in glob(['libs/*.jar']):
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)
create_aar_targets(glob(["libs/*.aar"]))

for aarfile in glob(['libs/*.aar']):
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
create_jar_targets(glob(["libs/*.jar"]))

android_library(
name = "all-libs",
Expand Down
13 changes: 7 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,25 @@ def enableProguardInReleaseBuilds = false

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.reactnativestyledtext"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
Expand All @@ -126,7 +127,7 @@ android {
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
Expand Down
19 changes: 19 additions & 0 deletions android/app/build_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Helper definitions to glob .aar and .jar targets"""

def create_aar_targets(aarfiles):
for aarfile in aarfiles:
name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")]
lib_deps.append(":" + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)

def create_jar_targets(jarfiles):
for jarfile in jarfiles:
name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")]
lib_deps.append(":" + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)
8 changes: 8 additions & 0 deletions android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativestyledtext">
package="com.reactnativestyledtext">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
Expand Down
20 changes: 7 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

buildscript {
ext {
buildToolsVersion = "27.0.3"
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
jcenter()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath('com.android.tools.build:gradle:3.4.1')

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -23,17 +23,11 @@ buildscript {
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
}


task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
18 changes: 17 additions & 1 deletion android/gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
Loading

0 comments on commit 61c6661

Please sign in to comment.