1 | # FadeView
|
2 |
|
3 | [![npm version](https://badgen.net/npm/v/@pietile-native-kit/fade-view?color=56C838)](https://www.npmjs.com/package/@pietile-native-kit/fade-view)
|
4 | [![install size](https://badgen.net/packagephobia/install/@pietile-native-kit/fade-view)](https://packagephobia.now.sh/result?p=@pietile-native-kit/fade-view)
|
5 |
|
6 | Changes content with _FadeOut-FadeIn_ animation. `FadeView` uses `data` prop to know when start
|
7 | the transition. Useful in situations when you want to change content smoothly, implementing tabs
|
8 | content for example.
|
9 |
|
10 | <img src="https://media.giphy.com/media/UowUvUvitH7sWZVjSY/giphy.gif" />
|
11 |
|
12 | ## Installation
|
13 |
|
14 | Using yarn
|
15 |
|
16 | ```sh
|
17 | yarn add @pietile-native-kit/fade-view
|
18 | ```
|
19 |
|
20 | or using npm
|
21 |
|
22 | ```sh
|
23 | npm install -S @pietile-native-kit/fade-view
|
24 | ```
|
25 |
|
26 | ## Usage
|
27 |
|
28 | Wrap the content in `FadeView` and set `data` to value that controls content. Every time data
|
29 | changes `FadeView` will remember children, play _FadeOut_ animation and then _FadeIn_ with current children
|
30 | already. So it's important to notice that `FadeView` passthrough children all the time except when
|
31 | playing _FadeOut_.
|
32 |
|
33 | ## Code example
|
34 |
|
35 | ```jsx
|
36 | import React, { Component } from 'react';
|
37 |
|
38 | import { StyleSheet, Text, TouchableOpacity } from 'react-native';
|
39 | import FadeView from '@pietile-native-kit/fade-view';
|
40 |
|
41 | class FadeViewExample extends Component {
|
42 | state = { isCat: true };
|
43 |
|
44 | onPress = () => this.setState(({ isCat }) => ({ isCat: !isCat }));
|
45 |
|
46 | render() {
|
47 | const { isCat } = this.state;
|
48 |
|
49 | return (
|
50 | <FadeView style={styles.container} data={isCat}>
|
51 | <TouchableOpacity
|
52 | style={[styles.touchable, { backgroundColor: isCat ? '#c4c' : '#bfb' }]}
|
53 | onPress={this.onPress}
|
54 | >
|
55 | <Text style={styles.text}>{isCat ? '🐱' : '🐶'}</Text>
|
56 | </TouchableOpacity>
|
57 | </FadeView>
|
58 | );
|
59 | }
|
60 | }
|
61 |
|
62 | const styles = StyleSheet.create({
|
63 | container: {
|
64 | ...StyleSheet.absoluteFillObject,
|
65 | justifyContent: 'center',
|
66 | alignItems: 'center',
|
67 | },
|
68 | touchable: {
|
69 | borderRadius: 16,
|
70 | padding: 16,
|
71 | },
|
72 | text: {
|
73 | fontSize: 86,
|
74 | },
|
75 | });
|
76 |
|
77 | export default FadeViewExample;
|
78 | ```
|
79 |
|
80 | ## API
|
81 |
|
82 | ### Properties
|
83 |
|
84 | | name | description | type | default |
|
85 | | :------- | :-------------------------------------------------------------- | -----: | :------ |
|
86 | | children | Content | Node | - |
|
87 | | data | Marker property for telling the FadeView to do _FadeOut-FadeIn_ | any | - |
|
88 | | duration | Hide and show animations duration | number | 150 |
|
89 | | style | Style of component | style | - |
|
90 |
|
91 | ## License
|
92 |
|
93 | Pietile FadeView is MIT License.
|