Skip to content

Commit

Permalink
backhandler bug catched
Browse files Browse the repository at this point in the history
  • Loading branch information
ippnsj committed Nov 16, 2020
1 parent 79a8e71 commit cbfed2a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from "react";
import { AsyncStorage, View } from 'react-native';
import { AsyncStorage, processColor, View } from 'react-native';
import WelcomeScreen from "./app/screens/WelcomeScreen";
import Home from "./app/screens/Home"
import Enrollment from "./app/screens/Enrollment";
Expand Down
2 changes: 2 additions & 0 deletions React/ict/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

require('events').EventEmitter.defaultMaxListeners = 100;

ReactDOM.render(<App />,
document.getElementById('root')
);
Expand Down
19 changes: 16 additions & 3 deletions app/screens/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class Board extends Component {
}

isFocused = () => {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);

this.setState({ category: this.props.route.params.BoardCategory });
if (this.props.route.params.BoardCategory == 0){
this.setState({BoardName: "전체 게시판"});
Expand All @@ -57,20 +59,31 @@ export default class Board extends Component {
this.getBoardContents();
}

isBlurred = () => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}

handleBackButton = () => {
if(this.props.navigation.isFocused()) {
this.props.navigation.navigate("Home");

return true;
}else {
return false;
}
}

componentDidMount() {
this._loadFonts();
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.addListener('focus', this.isFocused);
this.props.navigation.addListener('blur', this.isBlurred);
}

componentWillUnmount() {
this.props.navigation.removeListener('focus', this.isFocused);
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.removeListener('blur', this.isBlurred);
}

componentDidUpdate() {
}

Expand Down Expand Up @@ -115,7 +128,7 @@ export default class Board extends Component {
return res.json();
}).then((res) =>{
if (res.length == 0){
console.error("no favorite Post");
console.log("no favorite Post");
return;
}
let check = true;
Expand Down
13 changes: 8 additions & 5 deletions app/screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import {
View,
StyleSheet,
Image,
KeyboardAvoidingView,
TouchableOpacity,
BackHandler,
Alert
} from "react-native";
import * as Font from "expo-font";
import Constants from "expo-constants";
import * as DocumentPicker from 'expo-document-picker';
import { MyContext } from '../../context.js';
import { MyContext } from '../../context.js';

import colors from "../config/colors";
import Header from "./Header.js";
import { ScrollView } from 'react-native-gesture-handler';
import Unorderedlist from 'react-native-unordered-list';


export default class Home extends Component {
state = {
fontsLoaded: false,
Expand Down Expand Up @@ -64,19 +62,24 @@ export default class Home extends Component {

componentDidMount() {
this._loadFonts();
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.addListener('focus', this.isFocused);
this.props.navigation.addListener('blur', this.isBlurred);
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.removeListener('focus', this.isFocused);
this.props.navigation.removeListener('blur', this.isBlurred);
}

isFocused = () => {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
this.getBoardContents();
}

isBlurred = () => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}

async terminologyExplanation() {
let result = await DocumentPicker.getDocumentAsync({ type: "application/pdf" });
if(result.type === "success") {
Expand Down
3 changes: 3 additions & 0 deletions app/screens/Lawyer.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,12 @@ export default class Lawyer extends Component {
return(
<View style={{marginBottom:10}} key={idx}>
<Text style={styles.activity_text1}>{c.detail}</Text>
{c.url === null ?
null :
<View style={{flexDirection:"row"}}>
<Text style={styles.activity_text2} onPress={() => Linking.openURL(c.url)}>{c.url}</Text>
</View>
}
</View>
)
}) : <View>
Expand Down
1 change: 0 additions & 1 deletion app/screens/MyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default class MyPage extends Component {
}

isFocused = () => {
// this.scroll.scrollTo({x: 0, y: 0, animated: true});
const ctx = this.context;
this.setState({ introModVisible: false });

Expand Down
10 changes: 8 additions & 2 deletions app/screens/QaUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export default class QaUser extends Component {
}

isFocused = () => {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);

if(this.state.needToReset) {
this.handleEveryButtons();
}else {
Expand All @@ -105,6 +107,10 @@ export default class QaUser extends Component {
}
}

isBlurred = () => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}

handleBackButton = () => {
if(this.props.navigation.isFocused()) {
this.props.navigation.navigate("Home");
Expand All @@ -118,7 +124,7 @@ export default class QaUser extends Component {
async componentDidMount() {
this._loadFonts();
this.props.navigation.addListener('focus', this.isFocused);
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.addListener('blur', this.isBlurred);

const ctx = this.context;
const { userInt } = this.state;
Expand Down Expand Up @@ -206,7 +212,7 @@ export default class QaUser extends Component {

componentWillUnmount() {
this.props.navigation.removeListener('focus', this.isFocused);
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.removeListener('blur', this.isBlurred);
}

async handleEveryButtons() {
Expand Down
14 changes: 12 additions & 2 deletions app/screens/WelcomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ export default class WelcomeScreen extends Component {
}
}

isFocused = () => {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
}

isBlurred = () => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}

componentDidMount() {
this._loadFonts();
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.addListener('focus', this.isFocused);
this.props.navigation.addListener('blur', this.isBlurred);
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
this.props.navigation.removeListener('focus', this.isFocused);
this.props.navigation.removeListener('blur', this.isBlurred);
}

loginEvent() {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"react-native-screens": "~2.10.1",
"react-native-unordered-list": "^1.0.4",
"react-native-web": "~0.13.12",
"react-native-webview": "^10.9.2",
"react-native-webview": "10.7.0",
"react-navigation": "^4.4.2",
"react-navigation-drawer": "^2.6.0",
"react-redux": "^7.2.1",
Expand Down

0 comments on commit cbfed2a

Please sign in to comment.