├── .eslintrc
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── example
├── .babelrc
├── .flowconfig
├── .watchmanconfig
├── App.js
├── App.test.js
├── README.md
├── app.json
├── media
│ ├── example.gif
│ └── example2.gif
├── package.json
└── yarn.lock
├── index.js
├── package.json
└── react-native-text-ticker.d.ts
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "parser": "babel-eslint",
4 | "plugins": ["react"],
5 | "extends": [
6 | "standard",
7 | "plugin:react/recommended"
8 | ],
9 | "env": {
10 | "browser": true,
11 | "node": true,
12 | "es6": true,
13 | "jasmine": true,
14 | "mocha": true
15 | },
16 | "rules": {
17 | "array-bracket-spacing": 0,
18 | "brace-style": 2,
19 | "comma-dangle": ["warn", "never"],
20 | "comma-spacing": ["warn", {"before": false, "after": true}],
21 | "curly": 2,
22 | "indent": ["warn", 2, "SwitchCase": 1],
23 | "key-spacing": ["warn", {"beforeColon": false, "afterColon": true, "mode": "minimum", "align": "value"}],
24 | "keyword-spacing": [2, {"before": true, "after": true}],
25 | "max-len": ["warn", {"code": 100, "tabWidth": 2, "ignoreComments": true, "ignoreUrls": true, "ignoreTemplateLiterals": true, "ignoreTrailingComments": true}],
26 | "no-alert": 0,
27 | "no-console": 0,
28 | "no-multiple-empty-lines": [1, {"max": 3}],
29 | "no-param-reassign": 2,
30 | "no-sparse-arrays": 2,
31 | "no-trailing-spaces": 0,
32 | "no-unreachable": 2,
33 | "object-curly-spacing": 0,
34 | "padded-blocks": ["warn", { "switches": "always", "classes": "always" }],
35 | "prefer-const": ["error", {"destructuring": "any"}],
36 | "quote-props": [1, "as-needed"],
37 | "quotes": [2, "single", "avoid-escape"],
38 | "rest-spread-spacing": ["warn", "always"],
39 | "semi-spacing": [1, {"before": false, "after": true}],
40 | "semi": [1, "never"],
41 | "space-before-blocks": [1, "always"],
42 | "space-before-function-paren": [1, {"anonymous": "always", "named": "never"}],
43 | "space-in-parens": [1, "never"],
44 | "space-infix-ops": 1,
45 | "space-unary-ops": [1, {"words": true, "nonwords": false}],
46 | "spaced-comment": [1, "always"],
47 | "strict": 0,
48 | "react/display-name": 0,
49 | "react/no-danger": 0,
50 | "react/prop-types": 1,
51 | "react/no-unused-prop-types": 1
52 | },
53 | "parserOptions": {
54 | "sourceType": "module",
55 | "ecmaVersion": 6,
56 | "ecmaFeatures": {
57 | "jsx": true,
58 | "experimentalObjectRestSpread": true,
59 | "modules": true,
60 | "classes": true
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # expo
4 | .expo/
5 |
6 | # dependencies
7 | /node_modules
8 | /example/node_modules
9 |
10 | # misc
11 | .env.local
12 | .env.development.local
13 | .env.test.local
14 | .env.production.local
15 |
16 | npm-debug.log*
17 | yarn-debug.log*
18 | yarn-error.log*
19 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # node.js
6 | #
7 | ./expo
8 | example/
9 | node_modules/
10 | npm-debug.log
11 | yarn-error.log
12 |
13 | # vscode
14 | .vscode
15 | .eslintrc
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dean Hetherington
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-text-ticker
2 |
3 |
4 | ## Screenshot
5 | 
6 |
7 | 
8 |
9 | ## Description
10 | Inspired from the great [react-native-marquee](https://github.com/kyo504/react-native-marquee), this module acts similarly but with a few extra features and props:
11 |
12 | - Don't scroll the text if it fits in the container
13 | - Infinitely scroll text in a ticker fashion
14 | - Bounce text from side to side if it's only slightly wider than its container
15 | - Grab the text and scroll it manually
16 |
17 | To see it in action check out the example!
18 |
19 | This package aims to only support the latest version of React-Native.
20 |
21 | ## Installation
22 | ```
23 | npm install --save react-native-text-ticker
24 | or
25 | yarn add react-native-text-ticker
26 | ```
27 |
28 | ## Usage
29 | This module can be used as a drop in replacement for the react-native `Text` component (extra props optional).
30 |
31 | ```
32 | import React, { PureComponent } from 'react'
33 | import { StyleSheet, View } from 'react-native'
34 | import TextTicker from 'react-native-text-ticker'
35 |
36 | export default class Example extends PureComponent {
37 | render(){
38 | return(
39 |
40 |
48 | Super long piece of text is long. The quick brown fox jumps over the lazy dog.
49 |
50 |
51 | )
52 | }
53 | }
54 |
55 | const styles = StyleSheet.create({
56 | container: {
57 | flex: 1,
58 | justifyContent: 'center',
59 | alignItems: 'center',
60 | },
61 | });
62 |
63 | ```
64 |
65 | react-native-text-ticker supports a single child text string, any other use may give unexpected behaviour.
66 |
67 |
68 | ## Properties
69 | | Prop | Type | Optional | Default | Description
70 | |-----------------|-----------|----------|----------|-------------
71 | | style | StyleObj | true | - | Text Style
72 | | duration | number | true | `150ms` * length of string | Number of milliseconds until animation finishes
73 | | bounceSpeed | number | true | 50 | Describes how fast the bounce animation moves. Effective when duration is not set.
74 | | scrollSpeed | number | true | 150 | Describes how fast the scroll animation moves. Effective when duration is not set.
75 | | animationType | string | true | 'auto' | one of the values from 'auto', 'scroll', 'bounce'
76 | | loop | boolean | true | true | Infinitely scroll the text, effective when animationType is 'auto'
77 | | bounce | boolean | true | true | If text is only slightly longer than its container then bounce back/forwards instead of full scroll, effective when animationType is 'auto'
78 | | scroll | boolean | true | true | Gives the ability to grab the text and scroll for the user to read themselves. Will start scrolling again after `marqueeDelay` or `3000ms`
79 | | marqueeOnMount | boolean | true | true | Will start scroll as soon as component has mounted. Disable if using methods instead.
80 | | marqueeDelay | number | true | 0 | Number of milliseconds to wait before starting marquee
81 | | onMarqueeComplete | function | true | - | This function will run after the text has completely passed across the screen. Will run repeatedly if `loop` is enabled.
82 | | onScrollStart | function | true | - | This function will run if the text is long enough to trigger the scroll.
83 | | isInteraction | boolean | true | true | Whether or not animations create an interaction handle on the `InteractionManager`. Disable if you are having issues with VirtualizedLists not rendering properly.
84 | | useNativeDriver | boolean | true | true | Use native animation driver, should remain true for large majority of use-cases
85 | | repeatSpacer | number | true | 50 | The space between the end of your text string ticker and the beginning of it starting again.
86 | | bouncePadding | `{ left: number, right: number }` | true | - | The padding on start/end positions of bounce.
87 | | bounceDelay | number | true | 0 | How long the animation should wait after each bounce before starting again.
88 | | easing | function | true | Easing.ease | How the text scrolling animates. Additional options available from the [Easing module](https://facebook.github.io/react-native/docs/easing.html)
89 | | shouldAnimateTreshold | number | true | 0 | If you have a view drawn over the text at the right (a fade-out gradient for instance) this should be set to the width of the overlaying view: 
90 | | disabled | boolean | true | false | Disables text animation
91 | | isRTL | boolean | true | false | If text is right to left (By default, it uses `I18nManager.isRTL` to check)
92 |
93 | ## Methods
94 | These methods are optional and can be accessed by accessing the ref:
95 |
96 | | Prop | Params | Description
97 | |----------------|-----------|------------
98 | | startAnimation | delay | Start animation
99 | | stopAnimation | - | Stop animation
100 |
101 |
102 | ## License
103 | [MIT License](https://opensource.org/licenses/MIT)
104 |
--------------------------------------------------------------------------------
/example/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["babel-preset-expo"],
3 | "env": {
4 | "development": {
5 | "plugins": ["transform-react-jsx-source"]
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/example/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore templates for 'react-native init'
6 | /node_modules/react-native/local-cli/templates/.*
7 |
8 | ; Ignore RN jest
9 | /node_modules/react-native/jest/.*
10 |
11 | ; Ignore RNTester
12 | /node_modules/react-native/RNTester/.*
13 |
14 | ; Ignore the website subdir
15 | /node_modules/react-native/website/.*
16 |
17 | ; Ignore the Dangerfile
18 | /node_modules/react-native/danger/dangerfile.js
19 |
20 | ; Ignore Fbemitter
21 | /node_modules/fbemitter/.*
22 |
23 | ; Ignore "BUCK" generated dirs
24 | /node_modules/react-native/\.buckd/
25 |
26 | ; Ignore unexpected extra "@providesModule"
27 | .*/node_modules/.*/node_modules/fbjs/.*
28 |
29 | ; Ignore polyfills
30 | /node_modules/react-native/Libraries/polyfills/.*
31 |
32 | ; Ignore various node_modules
33 | /node_modules/react-native-gesture-handler/.*
34 | /node_modules/expo/.*
35 | /node_modules/react-navigation/.*
36 | /node_modules/xdl/.*
37 | /node_modules/reqwest/.*
38 | /node_modules/metro-bundler/.*
39 |
40 | [include]
41 |
42 | [libs]
43 | node_modules/react-native/Libraries/react-native/react-native-interface.js
44 | node_modules/react-native/flow/
45 | node_modules/expo/flow/
46 |
47 | [options]
48 | emoji=true
49 |
50 | module.system=haste
51 |
52 | module.file_ext=.js
53 | module.file_ext=.jsx
54 | module.file_ext=.json
55 | module.file_ext=.ios.js
56 |
57 | munge_underscores=true
58 |
59 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
60 |
61 | suppress_type=$FlowIssue
62 | suppress_type=$FlowFixMe
63 | suppress_type=$FlowFixMeProps
64 | suppress_type=$FlowFixMeState
65 | suppress_type=$FixMe
66 |
67 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)
68 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+
69 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
70 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
71 |
72 | unsafe.enable_getters_and_setters=true
73 |
74 | [version]
75 | ^0.56.0
76 |
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/example/App.js:
--------------------------------------------------------------------------------
1 | import React, { PureComponent } from 'react'
2 | import {
3 | StyleSheet,
4 | Text,
5 | View,
6 | TouchableOpacity
7 | } from 'react-native'
8 | import TextTicker from 'react-native-text-ticker'
9 |
10 |
11 |
12 | export default class App extends PureComponent {
13 | renderTresholdExample = () => {
14 | const overlayWidth = 40
15 | const lineHeight = 20
16 | const text = "This fits but there's this view at the right obstrucating the end."
17 | const example1 = "shouldAnimateTreshold={0} (default value):"
18 | const example2 = "shouldAnimateTreshold={40} (width of obstrucating view):"
19 | const example3 = "shouldAnimateTreshold={40} bounce={false}:"
20 | return (
21 |
22 |
23 | examples for the shouldAnimateTreshold prop:
24 |
25 | {example1}
26 |
27 |
28 | {text}
29 |
30 |
31 |
32 | {example2}
33 |
34 |
35 | {text}
36 |
37 |
38 |
39 | {example3}
40 |
41 |
42 | {text}
43 |
44 |
45 |
46 |
47 | )
48 | }
49 |
50 | render() {
51 | const Spacer = () =>
52 | return (
53 |
54 | this.marqueeRef.startAnimation()}>
55 | Start Animation
56 |
57 |
58 | this.marqueeRef.stopAnimation()}>
59 | Stop Animation
60 |
61 |
62 | this.marqueeRef = c}>
63 | Super long piece of text is long. The quick brown fox jumps over the lazy dog.
64 |
65 |
66 | console.log('Scroll Completed!')}>
67 | Super long piece of text is long. The quick brown fox jumps over the lazy dog.
68 |
69 |
70 |
71 | This fits in its container and wont scroll
72 |
73 |
74 |
75 | This is an example that's only slightly longer so it bounces sides
76 |
77 |
78 | {this.renderTresholdExample()}
79 |
80 | )
81 | }
82 |
83 | }
84 |
85 | const styles = StyleSheet.create({
86 | container: {
87 | flex: 1,
88 | backgroundColor: '#fff',
89 | alignItems: 'center',
90 | justifyContent: 'center'
91 | },
92 | spacer: {
93 | width: '85%',
94 | borderBottomWidth: 2,
95 | borderColor: 'grey',
96 | margin: 15
97 | },
98 | overlayView: {
99 | position: 'absolute',
100 | top: 0,
101 | bottom: 0,
102 | right: 0,
103 | opacity: 0.8
104 | },
105 | shouldAnimateTresholdContainer: {
106 | marginBottom: 20,
107 | height: 20
108 | }
109 | })
110 |
--------------------------------------------------------------------------------
/example/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import App from './App';
3 |
4 | import renderer from 'react-test-renderer';
5 |
6 | it('renders without crashing', () => {
7 | const rendered = renderer.create().toJSON();
8 | expect(rendered).toBeTruthy();
9 | });
10 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
2 |
3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md).
4 |
5 | ## Table of Contents
6 |
7 | * [Updating to New Releases](#updating-to-new-releases)
8 | * [Available Scripts](#available-scripts)
9 | * [npm start](#npm-start)
10 | * [npm test](#npm-test)
11 | * [npm run ios](#npm-run-ios)
12 | * [npm run android](#npm-run-android)
13 | * [npm run eject](#npm-run-eject)
14 | * [Writing and Running Tests](#writing-and-running-tests)
15 | * [Environment Variables](#environment-variables)
16 | * [Configuring Packager IP Address](#configuring-packager-ip-address)
17 | * [Adding Flow](#adding-flow)
18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon)
19 | * [Sharing and Deployment](#sharing-and-deployment)
20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community)
21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app)
22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app)
23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio)
24 | * [Should I Use ExpoKit?](#should-i-use-expokit)
25 | * [Troubleshooting](#troubleshooting)
26 | * [Networking](#networking)
27 | * [iOS Simulator won't open](#ios-simulator-wont-open)
28 | * [QR Code does not scan](#qr-code-does-not-scan)
29 |
30 | ## Updating to New Releases
31 |
32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never.
33 |
34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies.
35 |
36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility.
37 |
38 | ## Available Scripts
39 |
40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.
41 |
42 | ### `npm start`
43 |
44 | Runs your app in development mode.
45 |
46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.
47 |
48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script:
49 |
50 | ```
51 | npm start -- --reset-cache
52 | # or
53 | yarn start -- --reset-cache
54 | ```
55 |
56 | #### `npm test`
57 |
58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests.
59 |
60 | #### `npm run ios`
61 |
62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
63 |
64 | #### `npm run android`
65 |
66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App:
67 |
68 | ##### Using Android Studio's `adb`
69 |
70 | 1. Make sure that you can run adb from your terminal.
71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location).
72 |
73 | ##### Using Genymotion's `adb`
74 |
75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`.
76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)).
77 | 3. Make sure that you can run adb from your terminal.
78 |
79 | #### `npm run eject`
80 |
81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project.
82 |
83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up.
84 |
85 | ## Customizing App Display Name and Icon
86 |
87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key.
88 |
89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string.
90 |
91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency.
92 |
93 | ## Writing and Running Tests
94 |
95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html).
96 |
97 | ## Environment Variables
98 |
99 | You can configure some of Create React Native App's behavior using environment variables.
100 |
101 | ### Configuring Packager IP Address
102 |
103 | When starting your project, you'll see something like this for your project URL:
104 |
105 | ```
106 | exp://192.168.0.2:19000
107 | ```
108 |
109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides.
110 |
111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable:
112 |
113 | Mac and Linux:
114 |
115 | ```
116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
117 | ```
118 |
119 | Windows:
120 | ```
121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
122 | npm start
123 | ```
124 |
125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`.
126 |
127 | ## Adding Flow
128 |
129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept.
130 |
131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native.
132 |
133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps:
134 |
135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig)
136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number.
137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`.
138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`).
139 |
140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors.
141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience.
142 |
143 | To learn more about Flow, check out [its documentation](https://flow.org/).
144 |
145 | ## Sharing and Deployment
146 |
147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service.
148 |
149 | ### Publishing to Expo's React Native Community
150 |
151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account.
152 |
153 | Install the `exp` command-line tool, and run the publish command:
154 |
155 | ```
156 | $ npm i -g exp
157 | $ exp publish
158 | ```
159 |
160 | ### Building an Expo "standalone" app
161 |
162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself.
163 |
164 | ### Ejecting from Create React Native App
165 |
166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
167 |
168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html).
169 |
170 | #### Should I Use ExpoKit?
171 |
172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option.
173 |
174 | ## Troubleshooting
175 |
176 | ### Networking
177 |
178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports.
179 |
180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see:
181 |
182 | ```
183 | exp://192.168.0.1:19000
184 | ```
185 |
186 | Try opening Safari or Chrome on your phone and loading
187 |
188 | ```
189 | http://192.168.0.1:19000
190 | ```
191 |
192 | and
193 |
194 | ```
195 | http://192.168.0.1:19001
196 | ```
197 |
198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received.
199 |
200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager.
201 |
202 | ### iOS Simulator won't open
203 |
204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`:
205 |
206 | * "non-zero exit code: 107"
207 | * "You may need to install Xcode" but it is already installed
208 | * and others
209 |
210 | There are a few steps you may want to take to troubleshoot these kinds of errors:
211 |
212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so.
214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`.
215 |
216 | ### QR Code does not scan
217 |
218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
219 |
220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually.
221 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "sdkVersion": "25.0.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/example/media/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deanhet/react-native-text-ticker/7dfc8e654a79591b633e2cfd01376918d8e870ae/example/media/example.gif
--------------------------------------------------------------------------------
/example/media/example2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deanhet/react-native-text-ticker/7dfc8e654a79591b633e2cfd01376918d8e870ae/example/media/example2.gif
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "0.9.0",
4 | "private": true,
5 | "devDependencies": {
6 | "jest-expo": "25.0.0",
7 | "react-native-scripts": "1.11.1",
8 | "react-test-renderer": "16.2.0"
9 | },
10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
11 | "scripts": {
12 | "start": "react-native-scripts start",
13 | "eject": "react-native-scripts eject",
14 | "android": "react-native-scripts android",
15 | "ios": "react-native-scripts ios",
16 | "test": "node node_modules/jest/bin/jest.js"
17 | },
18 | "jest": {
19 | "preset": "jest-expo"
20 | },
21 | "dependencies": {
22 | "expo": "^25.0.0",
23 | "react": "16.2.0",
24 | "react-native": "0.52.0",
25 | "react-native-text-ticker": "0.13.0"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import React, { PureComponent } from 'react'
2 | import {
3 | Animated,
4 | Easing,
5 | StyleSheet,
6 | Text,
7 | View,
8 | ScrollView,
9 | NativeModules,
10 | findNodeHandle,
11 | I18nManager
12 | } from 'react-native'
13 |
14 | const { UIManager } = NativeModules
15 |
16 | export const TextTickAnimationType = Object.freeze({
17 | auto: 'auto',
18 | scroll: 'scroll',
19 | bounce: 'bounce'
20 | })
21 |
22 | export default class TextMarquee extends PureComponent {
23 | static defaultProps = {
24 | style: {},
25 | loop: true,
26 | bounce: true,
27 | scroll: true,
28 | marqueeOnMount: true,
29 | marqueeDelay: 0,
30 | isInteraction: true,
31 | useNativeDriver: true,
32 | repeatSpacer: 50,
33 | easing: Easing.ease,
34 | animationType: 'auto',
35 | bounceSpeed: 50,
36 | scrollSpeed: 150,
37 | bouncePadding: undefined,
38 | bounceDelay: 0,
39 | shouldAnimateTreshold: 0,
40 | disabled: false,
41 | isRTL: undefined
42 | }
43 |
44 | animatedValue = new Animated.Value(0)
45 | distance = null
46 | textRef = null
47 | containerRef = null
48 |
49 | state = {
50 | animating: false,
51 | contentFits: true,
52 | shouldBounce: false,
53 | isScrolling: false
54 | }
55 |
56 | constructor(props) {
57 | super(props);
58 | this.calculateMetricsPromise = null
59 | }
60 |
61 | componentDidMount() {
62 | this.invalidateMetrics()
63 | const { disabled, marqueeDelay, marqueeOnMount } = this.props
64 | if (!disabled && marqueeOnMount) {
65 | this.startAnimation(marqueeDelay)
66 | }
67 | }
68 |
69 | componentDidUpdate(prevProps) {
70 | if (this.props.children !== prevProps.children) {
71 | this.resetScroll()
72 | } else if (this.props.disabled !== prevProps.disabled) {
73 | if (!this.props.disabled && this.props.marqueeOnMount) {
74 | this.startAnimation(this.props.marqueeDelay)
75 | } else if (this.props.disabled) {
76 | // Cancel any promises
77 | if (this.calculateMetricsPromise !== null) {
78 | this.calculateMetricsPromise.cancel()
79 | this.calculateMetricsPromise = null
80 | }
81 | this.stopAnimation()
82 | this.clearTimeout()
83 | }
84 | }
85 | }
86 |
87 | componentWillUnmount() {
88 | // Cancel promise to stop setState after unmount
89 | if (this.calculateMetricsPromise !== null) {
90 | this.calculateMetricsPromise.cancel()
91 | this.calculateMetricsPromise = null
92 | }
93 | this.stopAnimation()
94 | // always stop timers when unmounting, common source of crash
95 | this.clearTimeout()
96 | }
97 |
98 | makeCancelable = (promise) => {
99 | let cancel = () => {}
100 | const wrappedPromise = new Promise((resolve, reject) => {
101 | cancel = () => {
102 | resolve = null
103 | reject = null
104 | };
105 | promise.then(
106 | value => {
107 | if (resolve) {
108 | resolve(value)
109 | }
110 | },
111 | error => {
112 | if (reject) {
113 | reject(error)
114 | }
115 | }
116 | );
117 | });
118 | wrappedPromise.cancel = cancel
119 | return wrappedPromise
120 | };
121 |
122 | startAnimation = () => {
123 | if (this.state.animating) {
124 | return
125 | }
126 | this.start()
127 | }
128 |
129 | animateScroll = () => {
130 | const {
131 | duration,
132 | marqueeDelay,
133 | loop,
134 | isInteraction,
135 | useNativeDriver,
136 | repeatSpacer,
137 | easing,
138 | children,
139 | scrollSpeed,
140 | onMarqueeComplete,
141 | isRTL
142 | } = this.props
143 | this.setTimeout(() => {
144 | const scrollToValue = isRTL ?? I18nManager.isRTL ? this.textWidth + repeatSpacer : -this.textWidth - repeatSpacer
145 | if(!isNaN(scrollToValue)) {
146 | Animated.timing(this.animatedValue, {
147 | toValue: scrollToValue,
148 | duration: duration || this.textWidth * scrollSpeed,
149 | easing: easing,
150 | isInteraction: isInteraction,
151 | useNativeDriver: useNativeDriver
152 | }).start(({ finished }) => {
153 | if (finished) {
154 | if (onMarqueeComplete) {
155 | onMarqueeComplete()
156 | }
157 | if (loop) {
158 | this.animatedValue.setValue(0)
159 | this.animateScroll()
160 | }
161 | }
162 | })} else {
163 | this.start()
164 | }
165 | }, marqueeDelay)
166 | }
167 |
168 | animateBounce = () => {
169 | const {duration, marqueeDelay, loop, isInteraction, useNativeDriver, easing, bounceSpeed, bouncePadding, bounceDelay, isRTL} = this.props
170 | const rtl = isRTL ?? I18nManager.isRTL;
171 | const bounceEndPadding = rtl ? bouncePadding?.left : bouncePadding?.right;
172 | const bounceStartPadding = rtl ? bouncePadding?.right : bouncePadding?.left;
173 | this.setTimeout(() => {
174 | Animated.sequence([
175 | Animated.timing(this.animatedValue, {
176 | toValue: rtl ? this.distance + (bounceEndPadding ?? 10) : -this.distance - (bounceEndPadding ?? 10),
177 | duration: duration || (this.distance) * bounceSpeed,
178 | easing: easing,
179 | isInteraction: isInteraction,
180 | useNativeDriver: useNativeDriver
181 | }),
182 | Animated.timing(this.animatedValue, {
183 | toValue: rtl ? -(bounceStartPadding ?? 10) : bounceStartPadding ?? 10,
184 | duration: duration || (this.distance) * bounceSpeed,
185 | easing: easing,
186 | isInteraction: isInteraction,
187 | useNativeDriver: useNativeDriver,
188 | delay: bounceDelay
189 | })
190 | ]).start(({finished}) => {
191 | if (finished) {
192 | this.hasFinishedFirstLoop = true
193 | }
194 | if (loop) {
195 | this.animateBounce()
196 | }
197 | })
198 | }, this.hasFinishedFirstLoop ? bounceDelay > 0 ? bounceDelay : 0 : marqueeDelay)
199 | }
200 |
201 | start = async () => {
202 | this.setState({ animating: true })
203 | this.setTimeout(async () => {
204 | await this.calculateMetrics()
205 | if (!this.state.contentFits) {
206 | const {onScrollStart} = this.props
207 | if(onScrollStart && typeof onScrollStart === "function") {
208 | onScrollStart()
209 | }
210 | if (this.props.animationType === 'auto') {
211 | if (this.state.shouldBounce && this.props.bounce) {
212 | this.animateBounce()
213 | } else {
214 | this.animateScroll()
215 | }
216 | } else if (this.props.animationType === 'bounce') {
217 | this.animateBounce()
218 | } else if (this.props.animationType === 'scroll') {
219 | this.animateScroll()
220 | }
221 | }
222 | }, 100)
223 | }
224 |
225 | stopAnimation() {
226 | this.animatedValue.setValue(0)
227 | this.setState({ animating: false, shouldBounce: false })
228 | }
229 |
230 | async calculateMetrics() {
231 | const {shouldAnimateTreshold} = this.props
232 | this.calculateMetricsPromise = this.makeCancelable(new Promise(async (resolve, reject) => {
233 | try {
234 | const measureWidth = node =>
235 | new Promise(async (resolve, reject) => {
236 | // nodehandle is not always there, causes crash. modified to check..
237 | const nodeHandle = findNodeHandle(node);
238 | if (nodeHandle) {
239 | UIManager.measure(nodeHandle, (x, y, w) => {
240 | // console.log('Width: ' + w)
241 | return resolve(w)
242 | })
243 | } else {
244 | return reject('nodehandle_not_found');
245 | }
246 | });
247 | const [containerWidth, textWidth] = await Promise.all([
248 | measureWidth(this.containerRef),
249 | measureWidth(this.textRef)
250 | ]);
251 |
252 | this.containerWidth = containerWidth
253 | this.textWidth = textWidth
254 | this.distance = textWidth - containerWidth + shouldAnimateTreshold
255 |
256 | // console.log(`distance: ${this.distance}, contentFits: ${this.state.contentFits}`)
257 | resolve({
258 | // Is 1 instead of 0 to get round rounding errors from:
259 | // https://github.com/facebook/react-native/commit/a534672
260 | contentFits: this.distance <= 1,
261 | shouldBounce: this.distance < this.containerWidth / 8
262 | })
263 | } catch (error) {
264 | console.warn('react-native-text-ticker: could not calculate metrics', error);
265 | }
266 | }))
267 | await this.calculateMetricsPromise.then((result) => {
268 | this.setState({
269 | contentFits: result.contentFits,
270 | shouldBounce: result.shouldBounce,
271 | })
272 | return []
273 | })
274 | }
275 |
276 | invalidateMetrics = () => {
277 | this.distance = null
278 | this.setState({ contentFits: true })
279 | }
280 |
281 | clearTimeout() {
282 | if (this.timer) {
283 | clearTimeout(this.timer)
284 | this.timer = null
285 | }
286 | }
287 |
288 | setTimeout(fn, time = 0) {
289 | this.clearTimeout()
290 | this.timer = setTimeout(fn, time)
291 | }
292 |
293 | scrollBegin = () => {
294 | this.setState({ isScrolling: true })
295 | this.animatedValue.setValue(0)
296 | }
297 |
298 | scrollEnd = () => {
299 | const { marqueeDelay } = this.props
300 |
301 | this.setTimeout(() => {
302 | this.setState({ isScrolling: false })
303 | this.start()
304 | }, marqueeDelay >= 0 ? marqueeDelay : 3000)
305 | }
306 |
307 | resetScroll = () => {
308 | this.scrollBegin()
309 | this.scrollEnd()
310 | }
311 |
312 | render() {
313 | const { style, children, repeatSpacer, scroll, shouldAnimateTreshold, disabled, isRTL, ... props } = this.props
314 | const { animating, contentFits, isScrolling } = this.state
315 | const additionalContainerStyle = {
316 | // This is useful for shouldAnimateTreshold only:
317 | // we use flex: 1 to make the container take all the width available
318 | // without this, if the children have a width smaller that this component's parent's,
319 | // the container would have the width of the children (the text)
320 | // In this case, it would be impossible to determine if animating is necessary based on the width of the container
321 | // (contentFits in calculateMetrics() would always be true)
322 | flex: shouldAnimateTreshold ? 1 : undefined
323 | }
324 | const animatedText = disabled ? null : (
325 | (this.containerRef = c)}
327 | horizontal
328 | scrollEnabled={scroll ? !this.state.contentFits : false}
329 | scrollEventThrottle={16}
330 | onScrollBeginDrag={this.scrollBegin}
331 | onScrollEndDrag={this.scrollEnd}
332 | showsHorizontalScrollIndicator={false}
333 | style={[StyleSheet.absoluteFillObject, (isRTL ?? I18nManager.isRTL) && { flexDirection: 'row-reverse' } ]}
334 | display={animating ? 'flex' : 'none'}
335 | onContentSizeChange={() => this.calculateMetrics()}
336 | >
337 | (this.textRef = c)}
339 | numberOfLines={1}
340 | {... props}
341 | style={[style, { transform: [{ translateX: this.animatedValue }], width: null }]}
342 | >
343 | {this.props.children}
344 |
345 | {!contentFits && !isScrolling
346 | ?
347 |
352 | {this.props.children}
353 |
354 | : null }
355 |
356 | );
357 | return (
358 |
359 |
364 | {this.props.children}
365 |
366 | {animatedText}
367 |
368 | )
369 | }
370 |
371 | }
372 |
373 | const styles = StyleSheet.create({
374 | container: {
375 | overflow: 'hidden'
376 | }
377 | })
378 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-text-ticker",
3 | "version": "1.14.0",
4 | "description": "React Native Text Ticker/Marquee Component",
5 | "main": "index.js",
6 | "types": "react-native-text-ticker.d.ts",
7 | "directories": {
8 | "example": "example"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git@github.com:deanhet/react-native-text-ticker.git"
13 | },
14 | "keywords": [
15 | "react-native",
16 | "marquee",
17 | "android",
18 | "ios",
19 | "text",
20 | "scroller",
21 | "ticker",
22 | "scrolling"
23 | ],
24 | "author": "Dean Hetherington ",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/deanhet/react-native-text-ticker/issues"
28 | },
29 | "homepage": "https://github.com/deanhet/react-native-text-ticker/"
30 | }
31 |
--------------------------------------------------------------------------------
/react-native-text-ticker.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'react-native-text-ticker' {
2 | import React from 'react';
3 | import { StyleProp, TextProps, TextStyle, EasingFunction } from 'react-native';
4 |
5 | export interface TextTickerProps extends TextProps {
6 | duration?: number;
7 | onMarqueeComplete?: () => void;
8 | onScrollStart?: () => void;
9 | style?: StyleProp;
10 | loop?: boolean;
11 | bounce?: boolean;
12 | scroll?: boolean;
13 | marqueeOnMount?: boolean;
14 | marqueeDelay?: number;
15 | bounceDelay?: number;
16 | isInteraction?: boolean;
17 | useNativeDriver?: boolean;
18 | repeatSpacer?: number;
19 | easing?: EasingFunction;
20 | animationType?: 'auto' | 'scroll' | 'bounce';
21 | scrollSpeed?: number;
22 | bounceSpeed?: number;
23 | shouldAnimateTreshold?: number;
24 | isRTL?: boolean;
25 | bouncePadding?: {
26 | left?: number;
27 | right?: number;
28 | }
29 | disabled?: boolean;
30 | }
31 |
32 | export interface TextTickerRef {
33 | startAnimation(): void;
34 | stopAnimation(): void;
35 | }
36 |
37 | export default class TextTicker extends React.Component { }
38 | }
39 |
--------------------------------------------------------------------------------