failed to implement responsive react slick can anyone solve - reactjs

explain the problem here..,whats is problem here,i want to make my slick responsive
const settings = {
centerMode: true,
centerPadding: '10px',
slidesToShow: 5,
speed: 500,
slidesToScroll: 1,
arrows: true,
dots: false,
responsive: [
{
breakpoint: 768,
settings: {
arrows: false,
slidesToShow: 3,
},
},
{
breakpoint: 480,
settings: {
arrows: false,
slidesToShow: 1,
},
},
],
};
import React from "react";
import Ddata from "./Ddata";
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
const DCard = () => {
const settings = {
centerMode: true,
centerPadding: '10px',
slidesToShow: 5,
speed: 500,
slidesToScroll: 1,
arrows: true,
dots: false,
responsive: [
{
breakpoint: 768,
settings: {
arrows: false,
slidesToShow: 3,
},
},
{
breakpoint: 480,
settings: {
arrows: false,
slidesToShow: 1,
},
},
],
};
return (
<>
<Slider {...settings}>
{Ddata.map((val, index) => {
return (
<>
<div className='product' key={index}>
<div className="box">
<div className='img'>
<img src={val.cover} alt='' width='100%'/>
</div>
<h4>{val.name}</h4>
<span>${val.price}</span>
</div>
</div>
</>
)
})}
</Slider>
</>
)
}
export default DCard```

Here is the solution.
I have code your problem.
It might help you just have a look.
Thank You for the consideration :)
App.js
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import Slider from "react-slick";
import "./App.css";
const Ddata = [
{
id: 1,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
{
id: 2,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
{
id: 3,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
{
id: 4,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
{
id: 5,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
{
id: 6,
cover:
"https://images.unsplash.com/photo-1655800030256-a14581f818bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60",
name: "car",
price: "10000",
},
];
function App() {
const settings = {
dots: true,
infinite: false,
speed: 500,
slidesToShow: 4,
slidesToScroll: 4,
arrows: false,
responsive: [
{
breakpoint: 320,
settings: { slidesToShow: 1, slidesToScroll: 1, infinite: false },
},
{
breakpoint: 768,
settings: { slidesToShow: 2, slidesToScroll: 2, infinite: false },
},
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true,
},
},
{
breakpoint: 2080,
settings: {
slidesToShow: 4,
slidesToScroll: 4,
infinite: true,
dots: true,
},
},
],
};
return (
<div className='container'>
<Slider {...settings}>
{Ddata.map((val, i) => (
<div key={val.id}>
<div className='card'>
<img src={val.cover} alt={val.name} />
<h4>{val.name}</h4>
<p>{val.price}</p>
</div>
</div>
))}
</Slider>
</div>
);
}
export default App;
App.css
body {
padding-top: 40px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.slick-slider {
margin: 30px auto 50px;
width: auto;
}
h3 {
background: #00558b;
color: #fff;
line-height: 100px;
text-align: center;
font-size: 36px;
margin: 10px;
padding: 2%;
position: relative;
}
.card {
padding: 8px;
position: relative;
margin: 15px;
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.25);
border-top: 6px solid #d8d8d8;
transition: all 0.3s ease-in-out;
z-index: 1;
text-align: center;
}
.card img {
width: 250px;
}
.card:hover {
border-top: 6px solid #0080ad;
cursor: pointer;
transform: translateY(0px);
}
.card h4 {
text-transform: uppercase;
color: #3e4042;
}
.card p {
line-height: 1.5;
}
.slick-prev {
background: black;
}
.slick-next {
background: black;
}
.slick-dots li {
margin: 0 16px;
}
.slick-dots li button:before {
content: " ";
background: #d8d8d8;
opacity: 1;
height: 4px;
width: 40px;
}
.slick-dots li.slick-active button:before {
content: " ";
background: #0080ad;
opacity: 1;
height: 4px;
width: 40px;
}

Related

React-codemirror2 (json editor)

I'm using the lib "react-codemirror2" to make a JSON editor. But I can't set the styles as I need. This is what I want to get
This is how I'm trying to implement, I've tried setting styles for various modifiers, but nothing helps, and the default styles don't change.:
export const CodeMirrorStyled = styled(CodeMirror)`
& .CodeMirror {
background: ${palette(EPaletteTheme.light_grey, 0)};
font-family: "Roboto", monospace;
font-size: 16px;
height: 198px;
}
& .cm-variable {
color: ${palette(EPaletteTheme.brand_blue, 0)};
}
/* stylelint-disable declaration-no-important */
& div {
&::-webkit-scrollbar {
width: 4px !important;
}
&::-webkit-scrollbar-track {
background: ${palette(EPaletteTheme.light_grey, 0)} !important;
}
&::-webkit-scrollbar-thumb {
background-color: ${palette(EPaletteTheme.grey, 0)} !important;
border-radius: 4px !important;
}
}
/* stylelint-enable declaration-no-important */
& .CodeMirror-gutters {
background: ${palette(EPaletteTheme.light_grey, 0)};
}
`;
<CodeMirrorStyled
value={httpBody}
options={{
theme: "default",
height: "auto",
viewportMargin: Infinity,
mode: {
name: "javascript",
json: true,
statementIndent: 2,
},
lineNumbers: true,
lineWrapping: true,
indentWithTabs: false,
tabSize: 2,
}}
onBeforeChange={(
editor: any,
data: any,
value: string
) => {
onChangeCodeEditor(value);
}}
/>

Page transition animation in framer motion (React)

As title says i wanna do a page transition like https://allhero.co.jp with framer motion in React Js
i tried:
.anim-page{
&,._red{
position: fixed;
top: 0;
width: 100%;
height: 100%;
z-index:999;
}
&._black{
background-color: black;
}
._red{
background-color: red;
}
}
//-------------------------------------
const page_anim = {
red: {
hidden: { scaleX: 0 },
visible: {
scaleX: [1, 0],
transformOrigin: 'right',
transition: { duration: 0.5, {delay:0.3} },
},
},
black: {
hidden: { right: '100%' },
visible: {
// skewX: ['-25deg', '0deg'],
right: '0%',
transition: { duration: 0.7 },
},
},
}
// -----------------------------------
<motion.div
className='anim-page _black'
variants={page_anim.black}
initial='hidden'
animate='visible'
>
<motion.div className='_red' variants={page_anim.red}></motion.div>
</motion.div>
it kinda looks like that, but i don't know if this is the proper right way of doing it and it doesn't look that much. Importantly i wanna make it reusable.
i liked the feature that the black goes away when page is loaded
I think this is a gsap thing, but i did, not that great but i like it
AnimLoading.jsx
import { motion } from 'framer-motion'
import React from 'react'
const AnimLoading = () => {
const page_anim = {
red: {
hidden: { scaleX: 0 },
visible: {
scaleX: [1, 0],
transformOrigin: 'right',
transition: { duration: 0.4, delay: 0.2 },
},
},
black: {
hidden: { right: '100%' },
visible: {
skewX: ['0deg', '-5deg', '0deg'],
right: ['100%', '0%'],
transition: { duration: 0.5 },
},
done: {
right: '-100%',
skewX: ['0deg', '-5deg', '0deg'],
transition: { duration: 0.5 },
},
},
text: {
hidden: { opacity: 0 },
visible: { opacity: 1, transition: { delay: 0.4 } },
done: { opacity: 0 },
},
}
return (
<motion.div
className='anim-page _black'
variants={page_anim.black}
initial='hidden'
animate='visible'
exit='done'
>
<motion.div className='_red' variants={page_anim.red}></motion.div>
<motion.h1 variants={page_anim.text} className='text-norm light'>
LOADING...
</motion.h1>
</motion.div>
)
}
export default AnimLoading
bit of scss
.anim-page{
&,._red{
position: fixed;
top: 0;
width: 100%;
height: 100%;
z-index:999;
}
&._black{
background-color: ${({ theme }) => theme.bg_light};
box-shadow: 0 2px 7px ${({ theme }) => theme.shadow_1};
}
._red{
width: 70%;
right: 0;
background-color: ${({ theme }) => theme.bg_blue};
}
h1{
line-height: 100vh;
font-size:7vw;
display: grid;
place-items: center;
}
}
App.js
const route = location.pathname.split('/')[1]
const [animate, setAnimate] = useState(false)
useEffect(() => {
setAnimate(true)
setTimeout(() => {
setAnimate(false)
}, 1000)
}, [route])
<AnimatePresence>{animate && <AnimLoading />}</AnimatePresence>
I'm using React Router, this happens all the time route changes...

How do I dynamically adjust the size of the React chart 2 pie chart

titles come dynamically. The number is not clear. That's why I can't give a fixed height. The graphic is getting smaller. How can I make the chart size dynamic ?
const options = {
legend: {
"position": "bottom",
align:'start',
display:true,
itemWrap: true,
},
responsive: true,
maintainAspectRatio: false,
animation: false,
};
<div className={styles['department-charts__card__altCard']}>
<Doughnut
data={doughnutData}
options={options}
/>
</div>
If the Legend is too much, the graphic gets smaller. With Legend, the chart does not appear in a separate container. When I check it looks like this
<canvas height="600" width="542" class="chartjs-render-monitor" style="display: block; height: 300px; width: 271px;"></canvas>
I want the cake to be at least 300 pixels. With Legend it will be more comfortable to check whether the pie is in a different container. How can I make this show dynamic? Pie does not appear at all on small screens. If there are 3 or 4 in some values, it is not a problem. If it's too much, it doesn't fit. I don't want to hide the legend
Amme hizmeti,
Ben bu şekilde çözdüm. Özel bir efsane yarattım
import { Doughnut } from 'react-chartjs-2';
const options = {
legend: {
"position": "bottom",
display:false,
},
responsive: true,
maintainAspectRatio: false,
animation: false,
offset:true
};
let chartInstance = null;
const DepartmentCharts = ({
t, departmentDistribution
}) => {
const keys = departmentDistribution.map(it => {
const key = it.key
return t(key)
}) || [t('salesAndMarketing'), t('ik'), t('management')]
const values = departmentDistribution.map(it => it.value) || [0, 0, 0]
const doughnutData = {
labels: keys,
datasets: [{
data: values,
backgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#8bc34a',
'#6c429b',
'#00a860',
'#0154a3',
'#f78f1e',
"#CCCC99",
"#666666",
"#FFCC66",
"#6699CC",
"#663366",
"#9999CC",
"#CCCCCC",
"#669999",
"#CCCC66",
"#CC6600",
"#9999FF",
"#0066CC",
"#99CCCC",
"#999999",
"#FFCC00",
"#009999",
"#99CC33",
"#FF9900",
"#999966",
"#66CCCC",
"#339966",
"#CCCC33",
"#003f5c",
"#665191",
"#a05195",
"#d45087",
"#2f4b7c",
"#f95d6a",
"#ff7c43",
"#ffa600",
"#EF6F6C",
"#465775",
"#56E39F",
"#59C9A5",
"#5B6C5D",
"#0A2342",
"#2CA58D",
"#84BC9C",
"#CBA328",
"#F46197",
"#DBCFB0",
"#545775"
],
hoverBackgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#8bc34a',
'#6c429b',
'#00a860',
'#0154a3',
'#f78f1e',
"#CCCC99",
"#666666",
"#FFCC66",
"#6699CC",
"#663366",
"#9999CC",
"#CCCCCC",
"#669999",
"#CCCC66",
"#CC6600",
"#9999FF",
"#0066CC",
"#99CCCC",
"#999999",
"#FFCC00",
"#009999",
"#99CC33",
"#FF9900",
"#999966",
"#66CCCC",
"#339966",
"#CCCC33",
"#003f5c",
"#665191",
"#a05195",
"#d45087",
"#2f4b7c",
"#f95d6a",
"#ff7c43",
"#ffa600",
"#EF6F6C",
"#465775",
"#56E39F",
"#59C9A5",
"#5B6C5D",
"#0A2342",
"#2CA58D",
"#84BC9C",
"#CBA328",
"#F46197",
"#DBCFB0",
"#545775"
]
}]
};
const handleClick = (e, index) => {
const ctx = chartInstance.chartInstance;
const meta = ctx.getDatasetMeta(0);
// See controller.isDatasetVisible comment
meta.data[index].hidden = !meta.data[index].hidden;
// Toggle strikethrough class
if (e.currentTarget.classList.contains("disable-legend")) {
//console.log("çizgiyi kaldır")
e.currentTarget.classList.remove("disable-legend");
e.currentTarget.style.textDecoration = "inherit";
} else {
//console.log("çizgi çiz")
e.currentTarget.classList.add("disable-legend");
e.currentTarget.style.textDecoration = "line-through";
}
chartInstance.chartInstance.update();
};
useEffect(() => {
const legend = chartInstance.chartInstance.generateLegend();
document.getElementById("legend").innerHTML = legend;
document.querySelectorAll("#legend li").forEach((item, index) => {
item.addEventListener("click", (e) => handleClick(e, index));
});
}, [doughnutData]);
return (
<div className={styles['department-charts']}>
<Card className={styles['department-charts__card']}>
<CardHeader
title={`${t('departmentTitle')}`}
align='center'
/>
<CardContent>
<div className={styles['department-charts__card__altCard']}>
<Doughnut
data={doughnutData}
options={options}
ref={input => {
chartInstance = input;
}}
/>
</div>
<div id="legend" className={styles['department-charts__card__altCard__legend']}/>
</CardContent>
</Card>
</div>
);
};
style.css - efsane kısmı sizin için yeterli olabilir
.department-charts {
height: 100%;
&__card {
height: 100%;
padding: 16px;
&__altCard{
min-height: 235px;
&__legend{
color: #666666;
ul{
list-style: none;
font: 12px Verdana;
white-space: nowrap;
display: inline-block;
padding-top: 20px;
font-family: "Helvetica Neue";
}
li{
cursor: pointer;
float: left;
padding-left: 7px;
span{
width: 36px;
height: 12px;
display: inline-block;
margin: 0 5px 8px 0;
vertical-align: -9.4px;
}
}
}
}
}
}
.disable-legend {
text-decoration: line-through;
}

How to display value with '%' react chart-race

i want to display at chart-race value with percentage. example 75%
however, the value of chart-race accepts only number. how would I able to include '%'
here's the code from 'https://www.npmjs.com/package/react-chart-race'
import React, { Component } from 'react';
import ChartRace from 'react-chart-race';
class Form extends Component{
constructor(props){
super(props);
this.state = {
data: []
};
setInterval(() => {
this.handleChange();
}, 0);
}
getRandomInt(min, max){
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
handleChange(){
const data = [
{ id: 0, title: 'Ayfonkarahisar', value: 10, color: '#50c4fe'},
{ id: 1, title: 'Kayseri', value: 20, color: '#3fc42d' },
{ id: 2, title: 'Muğla', value: 30, color: '#c33178' },
{ id: 3, title: 'Uşak', value: 40, color: '#423bce' },
{ id: 4, title: 'Sivas', value: 50, color: '#c8303b' },
{ id: 5, title: 'Konya', value: 60, color: '#2c2c2c' }
];
this.setState({ data });
}
render(){
return(
<div>
<ChartRace
data={this.state.data}
backgroundColor='#000'
width={760}
padding={12}
itemHeight={58}
gap={12}
titleStyle={{ font: 'normal 400 13px Arial', color: '#fff' }}
valueStyle={{ font: 'normal 400 11px Arial', color: 'rgba(255,255,255, 0.42)' }}
/>
</div>
);
}
}
export {Form}
I have made some changes in react-chart-race for label
Now, you do not need to use this dependency use below code in your project
Add this two files to your project
ChartRace.js
import React, { Component } from "react";
import "./chartstyle.css";
export default class ChartRace extends Component {
constructor(props) {
super(props);
this.state = {
data: this.props.data.sort((a, b) => b.value - a.value),
temp: this.props.data,
maxValue: Math.max.apply(Math, this.props.data.map(item => item.value)),
valueLabel: this.props.valueLabel
};
}
static getDerivedStateFromProps(nextProps, prevState) {
let newProps = [...nextProps.data];
return {
data: nextProps.data,
temp: newProps.sort((a, b) => b.value - a.value),
maxValue: Math.max.apply(Math, nextProps.data.map(item => item.value))
};
}
draw(item, index) {
const indis = this.state.temp.findIndex(temp => temp.id === item.id);
const translateY =
indis === 0
? this.props.padding
: this.props.padding +
indis * this.props.itemHeight +
indis * this.props.gap;
return (
<div
key={index}
className="raceItem"
style={{
height: this.props.itemHeight,
transform:
"translateY(" +
translateY +
"px) translateX(" +
this.props.padding +
"px)"
}}
>
<b
style={{
backgroundColor: item.color,
width:
(item.value / this.state.maxValue) *
(this.props.width - 120 - 2 * this.props.padding)
}}
/>
<span>
<em style={this.props.titleStyle}>{item.title}</em>
<i style={this.props.valueStyle}>
{item.value} {this.state.valueLabel}{" "}
</i>
</span>
</div>
);
}
render() {
return (
<div
className="raceArea"
style={{
backgroundColor: this.props.backgroundColor,
paddingTop: this.props.padding,
paddingBottom: this.props.padding,
width: this.props.width,
height:
2 * this.props.padding +
this.state.temp.length * this.props.itemHeight +
(this.state.temp.length - 1) * this.props.gap
}}
>
{this.state.data.map((item, index) => this.draw(item, index))}
</div>
);
}
}
ChartRace.defaultProps = {
data: [],
backgroundColor: "#f9f9f9",
width: 680,
padding: 20,
itemHeight: 38,
gap: 4,
titleStyle: { font: "normal 400 13px Arial", color: "#212121" },
valueStyle: { font: "normal 400 11px Arial", color: "#777" },
valueLabel: ""
};
chartstyle.css
.raceArea {
box-sizing: border-box;
position: relative;
}
.raceItem {
display: flex;
align-items: center;
position: absolute;
top: 0px;
left: 0px;
transition: all 1200ms;
}
.raceItem b {
height: 100%;
border-radius: 4px;
transition: all 600ms;
background: #dadada;
}
.raceItem span {
width: 112px;
margin-left: 8px;
display: flex;
flex-direction: column;
}
.raceItem em {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.raceItem i {
margin-top: 2px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
Import it like
import ChartRace from "./ChartRace";
Use it like
<ChartRace
data={this.state.data}
backgroundColor="#000"
width={760}
padding={12}
itemHeight={58}
gap={12}
valueLabel="%" // pass your label here
titleStyle={{ font: "normal 400 13px Arial", color: "#fff" }}
valueStyle={{
font: "normal 400 11px Arial",
color: "rgba(255,255,255, 0.42)"
}}
/>

React-native animation time series with percentage or alternative for it

I'm trying to port react component to React-Native using react-native's Animated
I managed to create the circle and it's orbit and working good.
but I don't know how to write those rules in react-native's Animated
in #keyframes fulfilling-bouncing-circle-spinner-orbit-animation I need to wait till the half of the animation then I should scale it down and up twice
and in #keyframes fulfilling-bouncing-circle-spinner-circle-animation I don't know how to add and remove styles using react native animation, kept thinking about it but I didn't come up with an idea.
So is there's a way to add time series and do what I want in those frames the same way
#keyframes works.
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const BouncingCircle = styled.div`
height: ${props => props.size}px;
width: ${props => props.size}px;
position: relative;
animation: fulfilling-bouncing-circle-spinner-animation infinite
${props => props.animationDuration}ms ease;
* {
box-sizing: border-box;
}
.orbit {
height: ${props => props.size}px;
width: ${props => props.size}px;
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
border: calc(${props => props.size}px * 0.03) solid ${props => props.color};
animation: fulfilling-bouncing-circle-spinner-orbit-animation infinite
${props => props.animationDuration}ms ease;
}
.circle {
height: ${props => props.size}px;
width: ${props => props.size}px;
color: ${props => props.color};
display: block;
border-radius: 50%;
position: relative;
border: calc(${props => props.size}px * 0.1) solid ${props => props.color};
animation: fulfilling-bouncing-circle-spinner-circle-animation infinite
${props => props.animationDuration}ms ease;
transform: rotate(0deg) scale(1);
}
#keyframes fulfilling-bouncing-circle-spinner-animation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#keyframes fulfilling-bouncing-circle-spinner-orbit-animation {
0% {
transform: scale(1);
}
50% {
transform: scale(1);
}
62.5% {
transform: scale(0.8);
}
75% {
transform: scale(1);
}
87.5% {
transform: scale(0.8);
}
100% {
transform: scale(1);
}
}
#keyframes fulfilling-bouncing-circle-spinner-circle-animation {
0% {
transform: scale(1);
border-color: transparent;
border-top-color: inherit;
}
16.7% {
border-color: transparent;
border-top-color: initial;
border-right-color: initial;
}
33.4% {
border-color: transparent;
border-top-color: inherit;
border-right-color: inherit;
border-bottom-color: inherit;
}
50% {
border-color: inherit;
transform: scale(1);
}
62.5% {
border-color: inherit;
transform: scale(1.4);
}
75% {
border-color: inherit;
transform: scale(1);
opacity: 1;
}
87.5% {
border-color: inherit;
transform: scale(1.4);
}
100% {
border-color: transparent;
border-top-color: inherit;
transform: scale(1);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
const defaultProps = {
size: 60,
color: '#fff',
animationDuration: 4000,
className: '',
};
const FulfillingBouncingCircleSpinner = ({
size,
color,
animationDuration,
className,
style,
...props
}) => (
<BouncingCircle
size={size}
color={color}
animationDuration={animationDuration}
className={`fulfilling-bouncing-circle-spinner${
className ? ' ' + className : ''
}`}
style={style}
{...props}
>
<div className="circle" />
<div className="orbit" />
</BouncingCircle>
);
FulfillingBouncingCircleSpinner.propTypes = propTypes;
FulfillingBouncingCircleSpinner.defaultProps = defaultProps;
export default FulfillingBouncingCircleSpinner;
/** #flow **/
import React, { useEffect, useState } from 'react';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
import { Animated, Easing, StyleSheet } from 'react-native';
import { AnimationUtils } from '../animationUtils';
type EpicProps = {
size?: number,
duration?: number,
color?: string,
style?: ViewStyleProp
};
const EpicDefaultProps = {
size: 200,
color: 'red',
duration: 1000
};
export const FulfillingBouncingCircleSpinner = ({ size, color, duration, style, ...props }: EpicProps) => {
const [animate] = useState(new Animated.Value(0));
const spinnerStyle = StyleSheet.create({
container: {
height: size,
width: size,
position: 'relative'
},
circle: {
height: size,
width: size,
borderColor: color,
borderRadius: size * 0.5,
position: 'relative',
borderWidth: size * 0.1
},
orbit: {
height: size,
width: size,
position: 'absolute',
top: 0,
left: 0,
borderColor: color,
borderRadius: size * 0.5,
borderWidth: size * 0.03
}
});
const containerRotation = AnimationUtils.interpolation(animate, [0, 1], ['0deg', '360deg']);
const circle = AnimationUtils.interpolation(animate, [0, 1], [1, 1.4]);
const orbit = AnimationUtils.interpolation(animate, [0, 1], [1, 0.8]);
useEffect(() => {
Animated.loop(
Animated.sequence([
Animated.timing(animate, { toValue: 1, duration: duration, useNativeDriver: true, easing: Easing.back() }),
Animated.timing(animate, { toValue: 0, duration: duration, useNativeDriver: true, easing: Easing.back() })
])
).start();
}, [animate, duration]);
return (
<Animated.View style={[style, spinnerStyle.container, { transform: [{ rotate: containerRotation }] }]} {...props}>
<Animated.View style={[spinnerStyle.circle, { transform: [{ scaleX: circle }, { scaleY: circle }] }]} />
<Animated.View style={[spinnerStyle.orbit, { transform: [{ scaleX: orbit }, { scaleY: orbit }] }]} />
</Animated.View>
);
};
FulfillingBouncingCircleSpinner.defaultProps = EpicDefaultProps;
I have spend it sometime on React animation docs and I have came up with a solution if anyone interested or can enhance it I would much appreciate it.
/** #flow **/
import React, { useEffect, useState } from 'react';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
import { Animated, Easing, StyleSheet } from 'react-native';
type EpicProps = {
size?: number,
duration?: number,
color?: string,
style?: ViewStyleProp
};
const EpicDefaultProps = {
size: 200,
color: 'red',
duration: 1000
};
export const FulfillingBouncingCircleSpinner = ({ size, color, duration, style, ...props }: EpicProps) => {
const [animate] = useState(new Animated.Value(0));
const spinnerStyle = StyleSheet.create({
container: {
height: size,
width: size,
position: 'relative'
},
circle: {
height: size,
width: size,
borderColor: color,
borderRadius: size * 0.5,
position: 'relative',
borderWidth: size * 0.1
},
orbit: {
height: size,
width: size,
borderColor: color,
position: 'absolute',
top: 0,
left: 0,
borderRadius: size * 0.5,
borderWidth: size * 0.03
}
});
const animateStyle = {
container: {
transform: [
{
rotate: animate.interpolate({
inputRange: [0, 9, 10],
outputRange: ['0deg', '360deg', '360deg']
})
}
]
},
orbit: {
transform: [
{
scale: animate.interpolate({
inputRange: [0, 6, 7, 8, 9, 10],
outputRange: [1, 1, 0.8, 1, 0.8, 1]
})
}
]
},
circle: {
transform: [
{
scale: animate.interpolate({
inputRange: [0, 6, 7, 8, 9, 10],
outputRange: [1, 1, 1.4, 1, 1.4, 1]
})
}
],
borderColor: animate.interpolate({
inputRange: [0, 4, 5, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
}),
borderTopColor: animate.interpolate({
inputRange: [0, 10],
outputRange: [color, color]
}),
borderRightColor: animate.interpolate({
inputRange: [0, 1, 2, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
}),
borderBottomColor: animate.interpolate({
inputRange: [0, 2, 3, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
})
}
};
useEffect(() => {
Animated.loop(
Animated.timing(animate, {
toValue: 10,
duration: duration * 4,
easing: Easing.inOut(Easing.ease)
})
).start();
}, [animate, duration]);
return (
<Animated.View style={[style, spinnerStyle.container, animateStyle.container]} {...props}>
<Animated.View style={[spinnerStyle.circle, animateStyle.circle]} />
<Animated.View style={[spinnerStyle.orbit, animateStyle.orbit]} />
</Animated.View>
);
};
FulfillingBouncingCircleSpinner.defaultProps = EpicDefaultProps;

Resources