Skip to content

Commit

Permalink
Fixed android bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AustineA committed Dec 30, 2019
1 parent 836f01a commit 797e78d
Show file tree
Hide file tree
Showing 34 changed files with 209 additions and 98 deletions.
18 changes: 12 additions & 6 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import React from "react";
import Home from "./screens/Home";
import styled from "styled-components";
import { Provider } from "react-redux";
import { createStore } from "redux";

const initialState = {
action: ""
isOpen: false,
letter: require("./assets/Letter_A.png"),
audio: ""
};

const reducer = (state = initialState, action) => {
switch (action.type) {
case "CLOSE_MODAL":
return { action: "closeModal" };
break;
return {
...state,
isOpen: false
};

case "OPEN_MODAL":
return { action: "openModal" };
break;
return {
letter: action.payload.letter,
isOpen: true,
audio: action.payload.audio
};

default:
return state;
Expand Down
16 changes: 7 additions & 9 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"slug": "abc",
"privacy": "public",
"sdkVersion": "36.0.0",
"platforms": [
"ios",
"android",
"web"
],
"platforms": ["ios", "android", "web"],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
Expand All @@ -20,11 +16,13 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
"supportsTablet": true,
"bundleIdentifier": "xyz.lunabase.abcforbabies"
},
"android": {
"package": "xyz.lunabase.abcforbabies"
}
}
}
Binary file modified assets/For_B.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/audio/A.mp3
Binary file not shown.
Binary file added assets/audio/B.mp3
Binary file not shown.
Binary file added assets/audio/C.mp3
Binary file not shown.
Binary file added assets/audio/D.mp3
Binary file not shown.
Binary file added assets/audio/E.mp3
Binary file not shown.
Binary file added assets/audio/F.mp3
Binary file not shown.
Binary file added assets/audio/G.mp3
Binary file not shown.
Binary file added assets/audio/H.mp3
Binary file not shown.
Binary file added assets/audio/I.mp3
Binary file not shown.
Binary file added assets/audio/J.mp3
Binary file not shown.
Binary file added assets/audio/K.mp3
Binary file not shown.
Binary file added assets/audio/L.mp3
Binary file not shown.
Binary file added assets/audio/M.mp3
Binary file not shown.
Binary file added assets/audio/N.mp3
Binary file not shown.
Binary file added assets/audio/O.mp3
Binary file not shown.
Binary file added assets/audio/P.mp3
Binary file not shown.
Binary file added assets/audio/Q.mp3
Binary file not shown.
Binary file added assets/audio/R.mp3
Binary file not shown.
Binary file added assets/audio/S.mp3
Binary file not shown.
Binary file added assets/audio/T.mp3
Binary file not shown.
Binary file added assets/audio/U.mp3
Binary file not shown.
Binary file added assets/audio/V.mp3
Binary file not shown.
Binary file added assets/audio/W.mp3
Binary file not shown.
Binary file added assets/audio/X.mp3
Binary file not shown.
Binary file added assets/audio/Y.mp3
Binary file not shown.
Binary file added assets/audio/Z.mp3
Binary file not shown.
63 changes: 49 additions & 14 deletions components/Modal.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useLayoutEffect } from "react";
import styled from "styled-components";
import { Animated, Easing } from "react-native";
import { Animated, Easing, TouchableWithoutFeedback } from "react-native";
import { useDispatch, useSelector } from "react-redux";
import { Audio } from "expo-av";

const Modal = () => {
const dispatch = useDispatch();
const isOpen = useSelector(state => state.isOpen);
const letter = useSelector(state => state.letter);
const audio = useSelector(state => state.audio);

const Modal = ({ isModal, letter, action }) => {
const [modal, setScale] = useState({
scale: new Animated.Value(0),
opacity: new Animated.Value(0)
});

useEffect(() => {
const closeModal = () => {
dispatch({
type: "CLOSE_MODAL"
});
};

useLayoutEffect(() => {
toggleScale();
});
playAudio(audio);
console.log("Display is ", isOpen);

return async () => {
await soundObject.unloadAsync();
};
}, [isOpen]);

const toggleScale = () => {
Animated.timing(modal.scale, {
toValue: 1,
duration: 1000,
duration: 300,
easing: Easing.in()
}).start();

Animated.timing(modal.opacity, {
toValue: 1,
duration: 1200,
duration: 400,
easing: Easing.in()
}).start();
};

const soundObject = new Audio.Sound();
const playAudio = async audio => {
try {
await soundObject.loadAsync(audio);
await soundObject.playAsync();
} catch (error) {
console.log("Audio no found");
}
};

return (
<AnimatedContainer style={{ display: isModal, opacity: modal.opacity }}>
<ModalView>
<AnimatedModal style={{ transform: [{ scale: modal.scale }] }}>
<Letter source={letter} />
</AnimatedModal>
</ModalView>
</AnimatedContainer>
<Container>
<TouchableWithoutFeedback
onPress={() => {
closeModal();
soundObject.unloadAsync();
}}
>
<ModalView>
<ModalBody>
<Letter source={letter} />
</ModalBody>
</ModalView>
</TouchableWithoutFeedback>
</Container>
);
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"expo": "~36.0.0",
"expo-av": "~8.0.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
Expand Down
110 changes: 74 additions & 36 deletions screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,93 @@ import styled from "styled-components";
import { LinearGradient } from "expo-linear-gradient";
import { FlatGrid } from "react-native-super-grid";
import { SafeAreaView, TouchableOpacity } from "react-native";
import { useSelector, useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";

import { Letters } from "../shared/Data";
import Modal from "../components/Modal";

const Home = () => {
const [isActive, setIsActive] = useState("none");
const [letter, setLetter] = useState(require("../assets/For_A.png"));
const dispatch = useDispatch();
const isOpen = useSelector(state => state.isOpen);

return (
<Container>
<Modal isModal={isActive} letter={letter} />
<LinearGradient
colors={["#fbd859", "#ff7800"]}
style={{
width: "100%",
alignItems: "center",
justifyContent: "center",
flex: 1
}}
>
<SafeAreaView>
<FlatGrid
itemDimension={130}
items={Letters}
renderItem={({ item, index }) => (
<TouchableOpacity
key={index}
onPress={() => {
setIsActive("flex");
setLetter(Letters[index].for);
console.log("You clicked", index);
}}
>
<Card>
<Image source={item.letter} />
</Card>
</TouchableOpacity>
)}
/>
</SafeAreaView>
</LinearGradient>
</Container>
<>
<Container>
<>{isOpen && <Modal />}</>
<LinearGradient
colors={["#fbd859", "#ff7800"]}
style={{
width: "100%",
alignItems: "center",
justifyContent: "center",
flex: 1,
paddingTop: 30
}}
>
<SafeAreaView>
<FlatGrid
itemDimension={130}
items={Letters}
renderItem={({ item, index }) => (
<TouchableOpacity
key={index}
onPress={() => {
dispatch({
type: "OPEN_MODAL",
payload: { letter: item.for, audio: item.audio }
});
console.log("[Home] Display ", isOpen);
}}
>
<Card>
<Image source={item.letter} />
</Card>
</TouchableOpacity>
)}
/>
</SafeAreaView>
</LinearGradient>
</Container>
</>
);
};

export default Home;

const Container = styled.View`
position: relative;
flex: 1;
height: 100%;
width: 100%;
z-index: 10;
`;

const ExtraComponent = styled.View`
position: relative;
width: 100%;
height: 100%;
background: transparent;
`;

const Mod = styled.View`
height: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.4);
top: 0;
left: 0;
z-index: 100;
justify-content: center;
align-items: center;
position: absolute;
`;

const Button = styled.Text`
background: white;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 20px;
padding-right: 20px;
border-radius: 12px;
`;

const Card = styled.View`
Expand Down
Loading

0 comments on commit 797e78d

Please sign in to comment.