Invisible Home Button - css

I am new to CSS and I am trying to get my home button to work. It seems like the CSS for the home button is conflicting with the code for the other buttons. My CSS for the button is at the bottom of this code and I kept the rest incase I missed something that could possibly conflict with the button:
.game {
min-height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
background: lightblue;
h1 {
text-align: center;
display: block;
margin: 2rem;
font-family: "Caveat", cursive;
font-size: 3rem;
}
h2 {
margin: 1rem;
}
img {
width: 10%;
border-radius: 20px;
border: 5px solid black;
margin: 1rem;
}
}
.main-body {
font-family: "Lato", sans-serif;
text-align: center;
}
//Temporary style. Will need to do this properly later
body {
text-align: center;
font-family: -apple-system, sans-serif;
}
.container {
width: 1060px;
margin: 0 auto;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20px;
}
button {
background-color: rgb(64, 154, 184);
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 25px;
outline: none;
margin: 2rem;
transition: 0.3s ease-in-out;
cursor: pointer;
&:hover {
background: rgb(47, 120, 144);
}
}
button:focus {
outline: 0;
}
#cards {
width: 1060px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.card {
width: 160px;
height: 160px;
margin-bottom: 20px;
}
.card:not(:nth-child(6n)) {
margin-right: 20px;
}
.c {
position: absolute;
max-width: 160px;
max-height: 160px;
width: 50ch;
height: 50ch;
cursor: pointer;
will-change: transform, opacity;
}
.front,
.back {
background-size: cover;
}
.back {
background-image: url("../img/CardBackBlue.png");
border: 5px solid rgb(58, 138, 165);
border-radius: 20px;
}
.front {
border: 5px solid rgb(58, 138, 165);
border-radius: 20px;
}
.home-button1 {
.home-button {
margin: 1rem;
border: none;
height: 4rem;
width: 4rem;
position: absolute;
top: 0;
right: 0;
background: lightblue;
outline: none;
padding: auto;
cursor: pointer;
& :hover {
background: rgb(83, 147, 168);
}
}
.home-pic {
margin: auto;
width: 90%;
border: none;
}
}
Here is the HTML:
// import React from "react";
import React, { useState, useEffect } from "react";
import { useSpring, animated as a } from "react-spring";
import HomeButton from "../img/home-button.svg";
import Background1 from "../img/cartoon-animals/card-1.png";
import Background13 from "../img/cartoon-animals/card-13.png";
import Background3 from "../img/cartoon-animals/card-3.png";
import Background4 from "../img/cartoon-animals/card-4.png";
import Background5 from "../img/cartoon-animals/card-5.png";
import Background6 from "../img/cartoon-animals/card-6.png";
import Background7 from "../img/cartoon-animals/card-7.png";
import Background8 from "../img/cartoon-animals/card-8.png";
import Background9 from "../img/cartoon-animals/card-9.png";
import Background14 from "../img/cartoon-animals/card-14.png";
import Background11 from "../img/cartoon-animals/card-11.png";
import Background12 from "../img/cartoon-animals/card-12.png";
export default function Game({ setPageStatus, pageStatus }) {
const [options, setOptions] = useState(null);
const [highScore, setHighScore] = useState(0);
//This will check to see if new score is high score
useEffect(() => {
const json = localStorage.getItem("memorygamehighscore");
const savedScore = JSON.parse(json);
if (savedScore) {
setHighScore(savedScore);
}
}, []);
return (
<div className={`game ${pageStatus ? "active-game" : ""}`}>
<div className="home-button1">
<button onClick={() => setPageStatus(0)} class="home-button">
<img className="home-pic" src={HomeButton} alt="Home Button" />
</button>
</div>
<h1>EduMemory</h1>
<h2>Memory Game</h2>
<div className="container">
<div>
<h4>High Score: {highScore}</h4>
</div>
<div>
{options === null ? (
<>
<button onClick={() => setOptions(12)}>Easy</button>
<button onClick={() => setOptions(18)}>Medium</button>
<button onClick={() => setOptions(24)}>Hard</button>
</>
) : (
<>
<button
onClick={() => {
const prevOptions = options;
setOptions(null);
setTimeout(() => {
setOptions(prevOptions);
}, 5);
}}
>
Start Over
</button>
<button onClick={() => setOptions(null)}>Main Menu</button>
</>
)}
</div>
</div>
{options ? (
<MemoryGame
options={options}
setOptions={setOptions}
highScore={highScore}
setHighScore={setHighScore}
/>
) : (
<h2>Choose a difficulty to begin!</h2>
)}
</div>
);
}
//Game Board. Put in another file
function MemoryGame({ options, setOptions, highScore, setHighScore }) {
const [game, setGame] = useState([]);
const [flippedCount, setFlippedCount] = useState(0);
const [flippedIndexes, setFlippedIndexes] = useState([]);
const colors = [
`url(${Background1})`,
`url(${Background13})`,
`url(${Background3})`,
`url(${Background4})`,
`url(${Background5})`,
`url(${Background6})`,
`url(${Background7})`,
`url(${Background8})`,
`url(${Background9})`,
`url(${Background14})`,
`url(${Background11})`,
`url(${Background12})`,
];
useEffect(() => {
const newGame = [];
for (let i = 0; i < options / 2; i++) {
const firstOption = {
id: 2 * i,
colorId: i,
color: colors[i],
flipped: false,
};
const secondOption = {
id: 2 * i + 1,
colorId: i,
color: colors[i],
flipped: false,
};
newGame.push(firstOption);
newGame.push(secondOption);
}
const shuffledGame = newGame.sort(() => Math.random() - 0.5);
setGame(shuffledGame);
}, []);
//Section that shows high score. Maybe change later as is a little confusing
useEffect(() => {
const finished = !game.some((card) => !card.flipped);
if (finished && game.length > 0) {
setTimeout(() => {
const bestPossible = game.length;
let multiplier;
if (options === 12) {
multiplier = 5;
} else if (options === 18) {
multiplier = 2.5;
} else if (options === 24) {
multiplier = 1;
}
const pointsLost = multiplier * (0.66 * flippedCount - bestPossible);
let score;
if (pointsLost < 100) {
score = 100 - pointsLost;
} else {
score = 0;
}
if (score > highScore) {
setHighScore(score);
const json = JSON.stringify(score);
localStorage.setItem("memorygamehighscore", json);
}
//was getting error "Unexpected use of 'confirm' no-restricted-globals". Just needed to add "window."below
const newGame = window.confirm(
"You Win!, SCORE: " + score + " New Game?"
);
if (newGame) {
const gameLength = game.length;
setOptions(null);
setTimeout(() => {
setOptions(gameLength);
}, 5);
} else {
setOptions(null);
}
}, 500);
}
}, [game]);
// Runs if two cards have been flipped
if (flippedIndexes.length === 2) {
const match =
game[flippedIndexes[0]].colorId === game[flippedIndexes[1]].colorId;
if (match) {
const newGame = [...game];
newGame[flippedIndexes[0]].flipped = true;
newGame[flippedIndexes[1]].flipped = true;
setGame(newGame);
const newIndexes = [...flippedIndexes];
newIndexes.push(false);
setFlippedIndexes(newIndexes);
} else {
const newIndexes = [...flippedIndexes];
newIndexes.push(true);
setFlippedIndexes(newIndexes);
}
}
if (game.length === 0) return <div>loading...</div>;
else {
return (
<div id="cards">
{game.map((card, index) => (
<div className="card" key={index}>
<Card
id={index}
color={card.color}
game={game}
flippedCount={flippedCount}
setFlippedCount={setFlippedCount}
flippedIndexes={flippedIndexes}
setFlippedIndexes={setFlippedIndexes}
/>
</div>
))}
</div>
);
}
}
//Card setup. should be in a separate file eventually
function Card({
id,
color,
game,
flippedCount,
setFlippedCount,
flippedIndexes,
setFlippedIndexes,
}) {
const [flipped, set] = useState(false);
const { transform, opacity } = useSpring({
opacity: flipped ? 1 : 0,
transform: `perspective(600px) rotateX(${flipped ? 180 : 0}deg)`,
config: { mass: 5, tension: 500, friction: 80 },
});
//Set timer, then flip the cards back
useEffect(() => {
if (flippedIndexes[2] === true && flippedIndexes.indexOf(id) > -1) {
setTimeout(() => {
set((state) => !state);
setFlippedCount(flippedCount + 1);
setFlippedIndexes([]);
}, 1000);
} else if (flippedIndexes[2] === false && id === 0) {
setFlippedCount(flippedCount + 1);
setFlippedIndexes([]);
}
}, [flippedIndexes]);
const onCardClick = () => {
if (!game[id].flipped && flippedCount % 3 === 0) {
set((state) => !state);
setFlippedCount(flippedCount + 1);
const newIndexes = [...flippedIndexes];
newIndexes.push(id);
setFlippedIndexes(newIndexes);
} else if (
flippedCount % 3 === 1 &&
!game[id].flipped &&
flippedIndexes.indexOf(id) < 0
) {
set((state) => !state);
setFlippedCount(flippedCount + 1);
const newIndexes = [...flippedIndexes];
newIndexes.push(id);
setFlippedIndexes(newIndexes);
}
};
return (
<div onClick={onCardClick}>
<a.div
className="c back"
style={{
opacity: opacity.interpolate((o) => 1 - o),
transform,
}}
/>
<a.div
className="c front"
style={{
opacity,
transform: transform.interpolate((t) => `${t} rotateX(180deg)`),
backgroundImage: color,
}}
/>
</div>
);
}
//export default Game;

Related

How to style previous siblings in react styled-components?

I have react component like this:
const StyledMenu = () => {
const [currentStep, setCurrentStep] = React.useState('template');
const steps = ['template', 'audience', 'demography', 'action'];
const goToNextStep = () => {
const index = steps.indexOf(currentStep);
setCurrentStep(steps[index + 1]);
};
const goToPreviousStep = () => {
const index = steps.indexOf(currentStep);
if (index === 0) {
return;
}
setCurrentStep(steps[index - 1]);
};
return(
<div>
<StepsWrapper>
{steps.map((step, index) => (
<Step key={step} active={step === currentStep} last={index === 3}>
<StepDescription>{step}</StepDescription>
</Step>
))}
</StepsWrapper>
</div>
)
}
const StepsWrapper = styled('div')`
display: grid;
grid-template-columns: repeat(4, 1fr);
width: 100%;
height: 69px;
line-height: 69px;
text-align: center;
position: relative;
top: 27px;
`;
const Step = styled('div')<{ active: boolean; last: boolean }>`
color: ${({ active }) =>
active ? '#44b3db' : '#c7e8f4'};
`;
const StepDescription = styled('div')`
width: 240px;
height: 29px;
font-family: Roboto;
font-size: 18px;
font-weight: 500;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: center;
text-transform: uppercase;
margin: 0 auto;
`;
and I'm trying to style the items which are before the active item. If the first item is active, then nothing will be styled. I want to achieve styles from these images:
and
and
How can I achieve this? Thanks in advance!
I achieved this by adding a new state for the active index, and to styled-component I sent a boolean if the active index is bigger than the index, so the indexes less than current active index will be styled differently as #vishnu mentioned in the comment above. The code looks now like this
const StyledMenu = () => {
const [currentStep, setCurrentStep] = React.useState('template');
const steps = ['template', 'audience', 'demography', 'action'];
//added this line of code
const [activeIndex, setActiveIndex] = React.useState(0);
const goToNextStep = () => {
const index = steps.indexOf(currentStep);
setCurrentStep(steps[index + 1]);
//set the new activeIndex
setActiveIndex(index + 1);
};
const goToPreviousStep = () => {
const index = steps.indexOf(currentStep);
if (index === 0) {
return;
}
setCurrentStep(steps[index - 1]);
//set the new activeIndex
setActiveIndex(index - 1);
};
return(
<div>
<StepsWrapper>
{steps.map((step, index) => (
//sending the checked props to the styled component
<Step key={step} active={step === currentStep} last={index
=== 3} checked={activeIndex > index}>
<StepDescription>{step}</StepDescription>
</Step>
))}
</StepsWrapper>
</div>
)
}
const StepsWrapper = styled('div')`
display: grid;
grid-template-columns: repeat(4, 1fr);
width: 100%;
height: 69px;
line-height: 69px;
text-align: center;
position: relative;
top: 27px;
`;
const Step = styled('div')<{ active: boolean; last: boolean;
checked: boolean }>`
//checking if component is marked to be styled differently
color: ${({ active, checked }) =>
active ? '#44b3db' : checked ? 'red' '#c7e8f4'};
`;
const StepDescription = styled('div')`
width: 240px;
height: 29px;
font-family: Roboto;
font-size: 18px;
font-weight: 500;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: center;
text-transform: uppercase;
margin: 0 auto;
`;

Can't get the bottom-margin to work on my App in react

As stated I have tried adding margin-bottom to the css file tha the App consumes and I have tried adding it to the inline app called pagination, but it's not working. How do I get the offset?
Here's my app component. I believe the problem stems somewhere along the bottom of the render() method.
import React, { Component } from 'react';
import styles from './App.module.css';
import { Card } from 'react-bootstrap';
import dateFormat from 'dateformat';
import 'bootstrap/dist/css/bootstrap.min.css'
class App extends Component {
state = {
results: null,
total: null,
total_pages: null,
per_page: null,
current_page: 1
}
componentDidMount() {
this.makeHttpRequestWithPage(1);
}
makeHttpRequestWithPage = async pageNumber => {
const response = await fetch(`http://127.0.0.1:8000/cfdilist/?page=${pageNumber}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
});
const data = await response.json();
this.setState({
results: data.results,
total: data.total,
total_pages: data.total_pages,
per_page: data.page_size,
current_page: data.page
});
}
render() {
console.dir(this.state.results)
let results, renderPageNumbers;
if (this.state.results !== null) {
results = this.state.results.map(result => (
<Card>
<Card.Title>entry: {result.id}</Card.Title>
<Card.Text><b>Name:</b> {result.issuer_name}</Card.Text>
<Card.Text><b>Date:</b> {dateFormat(result.date_issued, "mmmm dS, yyyy")}</Card.Text>
<Card.Text><b>RFC:</b> {result.issuer_rfc}</Card.Text>
<Card.Text><b>Amount:</b> {result.total_amount}$</Card.Text>
<Card.Text><b>cfdi XML:</b></Card.Text>
<textarea>{result.cfdi_xml}</textarea>
</Card>
));
}
const pageNumbers = [];
if (this.state.total !== null) {
for (let i = 1; i <= this.state.total_pages; i++) {
pageNumbers.push(i);
}
renderPageNumbers = pageNumbers.map(number => {
let classes = this.state.current_page === number ? styles.active : '';
if (number === 1 || number === this.state.total || (number >= this.state.current_page - 2 && number <= this.state.current_page + 2)) {
return (
<span key={number} className={classes} onClick={() => this.makeHttpRequestWithPage(number)}>{number}</span>
);
}
});
}
return (
<div className={styles.app}>
<div className={styles.header}>
<h1>CFDI Page</h1>
</div>
{results}
<div className={styles.pagination}>
<span onClick={() => this.makeHttpRequestWithPage(1)}>«</span>
{renderPageNumbers}
<span onClick={() => this.makeHttpRequestWithPage(1)}>»</span>
</div>
</div>
);
}
}
export default App;
And here's my App.module.css
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px auto;
}
.Header {
width: 70%;
text-align: center;
margin: 0 auto;
margin-bottom: 50px;
}
.pagination {
margin-top: 25px;
margin-bottom: 40px;
}
.pagination span {
cursor: pointer;
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.pagination span.active {
background-color: #0099FF;
color: white;
border: 1px solid #0099FF;
}
There is an error in your css:
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px auto;
}
Should be:
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px; <-remove auto
}
Is your class being triggered if you inspect elements on your app?
EG: <div className="app">

Prevent page jump on Button click? ReactJS

I have a ShowcaseMovie component which fetches data on componentDidMount() and sets it to state. The component renders Card components to display the data as well as four button elements upcoming, top_rated, popular and now_playing which allow the user to toggle between the relevant data. Each button has an onClick event which calls changeFilter and sets state currentFilter to the selected key.
The problem: When the filter buttons are clicked, sometimes the page will jump to the top (if it's not already there). I've tried to find solutions to this but I can't seem to understand what is happening. Any suggestions will be a great help, thank you in advance.
Update: This issue seems to happen when there is no height set to an element with dynamic children. If I set the height on ShowcaseMovie to something large like height: 200vh it goes away.
I believe I've solved my problem but would love to hear other thoughts as to why this happens and some other ways to fix it. It's difficult to set a height to a parent when you don't know how much content is going to be rendered (or the height of that content). min-height would help but still kind of a quick fix.
ShowcaseMovie.js
import React, { Component } from "react";
import Card from "./Card";
import "../css/ShowcaseMovie.css";
import { v4 as uuidv4 } from "uuid";
import { formatString, buildMovieState } from "../utilities";
class ShowcaseMovie extends Component {
static defaultProps = {
filterNames: ["upcoming", "popular", "now_playing", "top_rated"]
};
constructor(props) {
super(props);
this.state = {
upcoming: [],
now_playing: [],
popular: [],
top_rated: [],
currentFilter: this.props.filterNames[0]
};
}
changeFilter = e => {
e.preventDefault();
const type = e.target.name;
this.setState({ currentFilter: type });
};
componentDidMount() {
this.props.filterNames.map(name => this.fetchMovies(name));
// setInterval(() => {
// this.timeoutFilter();
// }, 10000);
}
async fetchMovies(type) {
try {
const res = await fetch(
`url`
);
const data = await res.json();
if (data) {
this.setState(state => ({
...state,
[type]: buildMovieState(data)
}));
}
} catch (error) {
console.log(error);
}
}
render() {
const { currentFilter } = this.state;
const movies = this.state[currentFilter].map((movie, i) => (
<Card key={uuidv4()} movie={movie} index={i} />
));
const buttons = this.props.filterNames.map(name => (
<button
type="button"
key={name}
name={name}
className={`ShowcaseMovie-btn ${
currentFilter === name ? "active" : ""
}`}
disabled={currentFilter === name}
onClick={this.changeFilter}>
{formatString(name)}
</button>
));
return (
<section className="ShowcaseMovie">
<div className="ShowcaseMovie-container">
<h2 className="ShowcaseMovie-header">Movies</h2>
<div className="ShowcaseMovie-btn-container">{buttons}</div>
</div>
<div className="ShowcaseMovie-grid">{movies}</div>
</section>
);
}
}
ShowcaseMovie.css
.ShowcaseMovie {
padding: 4rem 10%;
}
.ShowcaseMovie-container {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
}
.ShowcaseMovie-button-container {
display: flex;
justify-content: center;
align-items: center;
}
.ShowcaseMovie-container::after {
content: "";
background-color: #64b5f6;
height: 80%;
width: 6px;
left: 0;
position: absolute;
border-radius: 1px;
}
.ShowcaseMovie-header {
font-size: 3rem;
font-weight: 200;
margin: 0 5rem;
}
.ShowcaseMovie-btn {
outline: none;
border: none;
background-color: transparent;
font-size: 1.6rem;
font-weight: 500;
letter-spacing: 1px;
padding: 1rem;
margin-left: 4rem;
color: white;
opacity: 0.5;
cursor: pointer;
transition-property: opacity;
transition-duration: 300ms;
transition-timing-function: ease;
}
.ShowcaseMovie-btn:hover {
opacity: 1;
transition-property: opacity;
transition-duration: 300ms;
transition-timing-function: ease;
}
.ShowcaseMovie-btn.active {
opacity: 1;
cursor: auto;
color: #64b5f6;
}
.ShowcaseMovie-grid {
display: grid;
gap: 3rem;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
Card.js
import React, { Component } from "react";
import "../css/Card.css";
class Card extends Component {
render() {
const { title, poster_path } = this.props.movie;
const style = { animationDelay: `${80 * this.props.index}ms` };
return (
<div className="Card">
<div className="Card-inner" style={style}>
<img
src={`https://image.tmdb.org/t/p/w500/${poster_path}`}
alt=""
className="Card-img"
/>
<p className="Card-name">{title}</p>
</div>
</div>
);
}
}
export default Card;
Card.css
.Card {
display: block;
transition: transform 300ms ease;
}
.Card:hover {
transform: translateY(-5px);
transition: transform 300ms ease;
}
.Card-inner {
position: relative;
display: block;
cursor: pointer;
height: 100%;
opacity: 0;
animation-name: moveUp;
animation-duration: 500ms;
animation-delay: 50ms;
animation-timing-function: ease;
animation-fill-mode: forwards;
}
.Card-inner::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: linear-gradient(transparent, rgba(33, 47, 61, 0.8));
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
z-index: 100;
opacity: 1;
transition: opacity 300ms ease;
}
.Card-inner:hover::after {
opacity: 0;
transition: opacity 300ms ease;
}
.Card-inner::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: linear-gradient(transparent, rgba(100, 180, 246, 0.6));
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
z-index: 100;
opacity: 0;
transition: opacity 300ms ease;
}
.Card-inner:hover::before {
opacity: 1;
transition: opacity 300ms ease;
}
.Card-img {
display: block;
position: relative;
object-fit: cover;
max-width: 100%;
min-height: 100%;
z-index: 0;
border-radius: 2px;
}
.Card-name {
position: absolute;
bottom: 0;
left: 0;
margin: 0 2rem 2rem 2rem;
z-index: 150;
font-weight: 400;
text-transform: uppercase;
font-size: 1.4rem;
letter-spacing: 2px;
}
#keyframes moveUp {
0% {
transform: translateY(5rem);
}
100% {
transform: translateY(0);
opacity: 1;
}
}
utilities.js
export const formatString = name => {
return name
.replace("_", " ")
.split(" ")
.map(w => w[0].toUpperCase() + w.slice(1))
.join(" ");
};
export const buildMovieState = data => {
if (data.results) {
const movies = data.results.filter(
d => d.backdrop_path && d.id && d.title && d.poster_path
);
return movies.length > 10 ? movies.slice(0, 10) : movies;
} else {
return [];
}
};
I was able to stop this from happening by returning false from the onClick call. Like this:
onClick={
doSomething()
return false
}
The page jumping could be from components unnecessarily re-rendering. Try wrapping all your components with React.memo( component name)

"auth/network-request-failed" when attempt to sign-in with firebase in react native app

I'm facing an issue when I try to sign-in with Firebase (v6) in my react native app.
this is the issue :
this is my code :
Firebase.js
this is the function which allow us to initialize app with firebaseConfig
import {firebase} from '#react-native-firebase/auth';
const firebaseConfig = {
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
authDomain: 'xxxxxxxx.firebaseapp.com',
databaseURL: 'https://xxxxxxxx.firebaseio.com',
projectId: 'xxxxxxxxx',
storageBucket: 'xxxxxxxxx.appspot.com',
messagingSenderId: 'xxxxxxxxxx',
appId: 'xxxxxxxxxxx'
};
firebase.initializeApp(firebaseConfig);
export default firebase;
ModalLogin.js
this is the main code from where the sign-in is checked.
import React from 'react';
import styled from 'styled-components';
import {
TouchableOpacity,
Alert,
Dimensions,
Animated,
TouchableWithoutFeedback,
Keyboard,
} from 'react-native';
import {BlurView, VibrancyView} from '#react-native-community/blur';
import {connect} from 'react-redux';
import Success from './Success';
import Loading from './Loading';
import firebase from './Firebase';
import auth from '#react-native-firebase/auth';
const screenHeight = Dimensions.get('window').height;
function mapStateToProps(state) {
return {action: state.action};
}
function mapDispatchToProps(dispatch) {
return {
closeLogin: () =>
dispatch({
type: 'CLOSE_LOGIN',
}),
};
}
class ModalLogin extends React.Component {
state = {
email: '',
password: '',
iconEmail: require('../Images/icon-email.png'),
iconPassword: require('../Images/icon-password.png'),
isSuccessful: false,
isLoading: false,
scale: new Animated.Value(1),
translateY: new Animated.Value(0),
top: new Animated.Value(screenHeight),
};
componentDidUpdate() {
if (this.props.action == 'openLogin') {
Animated.timing(this.state.top, {
toValue: 0,
duration: 0,
}).start();
Animated.spring(this.state.scale, {toValue: 1}).start();
Animated.timing(this.state.translateY, {
toValue: 0,
duration: 0,
}).start();
}
if (this.props.action == 'closeLogin') {
setTimeout(() => {
Animated.timing(this.state.top, {
toValue: screenHeight,
duration: 0,
}).start();
Animated.spring(this.state.scale, {toValue: 1.3}).start();
}, 500);
Animated.timing(this.state.translateY, {
toValue: 1000,
duration: 500,
}).start();
}
}
handleLogin = () => {
this.setState({isLoading: true});
const email = this.state.email;
const password = this.state.password;
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.catch(function(error) {
Alert.alert('Error', error.message);
})
.then(response => {
console.log(response);
this.setState({isLoading: false});
if (response) {
// Successful
this.setState({isSuccessful: false});
//storage
//this.storeName(response.user.email);
this.fetchUser();
this.props.updateName(response.user.email);
//
Alert.alert('Congrats', "You've logged in successfully!");
setTimeout(() => {
Keyboard.dismiss();
this.props.closeLogin();
this.setState({isSuccessful: false});
}, 1000);
console.log(response.user);
}
});
};
// change the image on tape
focusEmail = () => {
this.setState({
iconEmail: require('../Images/icon-email-animated.gif'),
iconPassword: require('../Images/icon-password.png'),
});
};
focusPassword = () => {
this.setState({
iconEmail: require('../Images/icon-email.png'),
iconPassword: require('../Images/icon-password-animated.gif'),
});
};
tapBackground = () => {
Keyboard.dismiss();
this.props.closeLogin();
};
render() {
return (
<AnimatedContainer style={{top: this.state.top}}>
<TouchableWithoutFeedback onPress={this.tapBackground}>
<BlurView
tint="default"
intensity={100}
style={{position: 'absolute', width: '100%', height: '100%'}}
/>
</TouchableWithoutFeedback>
<AnimatedModal
style={{
transform: [
{scale: this.state.scale},
{translateY: this.state.translateY},
],
}}>
<Logo source={require('../Images/Film.png')} />
<Text> Enjoy watching.</Text>
<TextInput
onChangeText={email => this.setState({email})}
placeholder="Email"
value={this.state.email}
keyboardType="email-address"
onFocus={this.focusEmail}
/>
<TextInput
onChangeText={password => this.setState({password})}
placeholder="Password"
value={this.state.password}
secureTextEntry={true}
onFocus={this.focusPassword}
/>
<IconEmail source={this.state.iconEmail} />
<IconPassword source={this.state.iconPassword} />
<TouchableOpacity onPress={this.handleLogin}>
<ButtonView>
<ButtonText>Log in</ButtonText>
</ButtonView>
</TouchableOpacity>
</AnimatedModal>
<Success isActive={this.state.isSuccessful} />
<Loading isActive={this.state.isLoading} />
</AnimatedContainer>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(ModalLogin);
const Container = styled.View`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.75);
justify-content: center;
align-items: center;
`;
const AnimatedContainer = Animated.createAnimatedComponent(Container);
const TextInput = styled.TextInput`
border: 1px solid #dbdfea;
width: 295px;
height: 44px;
border-radius: 10px;
font-size: 17px;
color: #3c4560;
padding-left: 44px;
margin-top: 20px;
`;
const Modal = styled.View`
width: 335px;
height: 370px;
border-radius: 20px;
background: white;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
align-items: center;
`;
const AnimatedModal = Animated.createAnimatedComponent(Modal);
const Logo = styled.Image`
width: 44px;
height: 44px;
margin-top: 50px;
`;
const Text = styled.Text`
margin-top: 20px;
font-size: 13px;
font-weight: 600;
text-transform: uppercase;
width: 160px;
color: #b8bece;
text-align: center;
`;
const ButtonView = styled.View`
background: #5263ff;
width: 295px;
height: 50px;
justify-content: center;
align-items: center;
border-radius: 10px;
margin-top: 20px;
box-shadow: 0 10px 20px #c2cbff;
`;
const ButtonText = styled.Text`
color: white;
text-transform: uppercase;
font-weight: 600;
font-size: 20px;
`;
const IconEmail = styled.Image`
width: 24px;
height: 22px;
position: absolute;
top: 160px;
left: 31px;
`;
const IconPassword = styled.Image`
width: 28px;
height: 28px;
position: absolute;
top: 229px;
left: 30px;
`;
Normally, it should work. I don't know where is the problem.
Can you help me with a solution please?
thank you
You need to stop Remote JS Debugging, and then run again:react-native run-ios
There is a problem in debugging since >0.6.
You can try with: react-native log-ios for debugging or use a bunch of Alerts.

Changing the default color of placeholder in react-virtualized-select

Tried changing the default color of the placeholder of my react-virtualized-select element using both input::-webkit-input-placeholder as well as singleValue property but it doesn't work. I even tried wrapping the entire code in a custom theme where the primary color was blue but it didn't work too. I want it to change it to the color that is in the textfield placeholder.
import "react-select/dist/react-select.css";
import "react-virtualized/styles.css";
import "react-virtualized-select/styles.css";
import "material-components-web/dist/material-components-web.css";
import "./react-select.css";
import React from "react";
import ReactDOM from "react-dom";
import Select from "react-virtualized-select";
import TextField from "rmwc/TextField";
const colourStyles = {
singleValue: styles => ({ ...styles, color: "blue" })
};
const options = Array.from(new Array(10), (_, index) => ({
label: `Item ${index}`,
value: index
}));
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
option: undefined
};
}
render() {
return (
<React.Fragment>
<Select
className={"mdc-react-select"}
value={this.state.option}
onChange={option => this.setState({ option })}
styles={colourStyles}
options={options}
inputRenderer={props => {
return (
<TextField
{...props}
fullwidth
ref={undefined}
inputRef={props.ref}
placeholder={"Farm"}
required
value={
props.value ||
(this.state.option ? this.state.option.label : undefined)
}
/>
);
}}
/>
<br />
<br />
<div>
<TextField
ref={undefined}
label={"Farm"}
value={this.state.option ? this.state.option.label : undefined}
style={{ width: "100%" }}
/>
</div>
</React.Fragment>
);
}
}
ReactDOM.render(<Foo />, document.getElementById("root"));
CSS:
body {
font-family: "Roboto";
}
.mdc-react-select .Select-placeholder,
.mdc-react-select .Select-value {
display: none;
}
.mdc-react-select .Select-control {
background-color: transparent;
border-color: none;
border-radius: 0;
border: none;
color: #333;
cursor: default;
display: table;
border-spacing: 0;
border-collapse: separate;
height: 36px;
outline: none;
overflow: hidden;
position: relative;
width: 100%;
box-shadow: none !important;
}
.mdc-react-select .Select-input {
opacity: 1 !important;
width: 100%;
}
.mdc-text-field .mdc-line-ripple{
background-color: rgb(23,87,170);
}
.mdc-floating-label .mdc-floating-label--float-above{
color: rgb(23,87,170) !important;
}
.mdc-text-field--focused:not(.mdc-text-field--disabled) .mdc-floating-label{
color:rgb(23,87,170) !important;
}
/* .mdc-text-field--invalid:not(.mdc-text-field--disabled):not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) .mdc-text-field__input:hover{
color:rgb(23,87,170) !important;
} */
/* input::-webkit-input-placeholder {
color: #999;
} */
Try this:
.mdc-react-select .Select-input {
color: red;
}
.mdc-react-select .Select-placeholder {
color: red;
}

Resources