bluejoyq

add react-reduct for better state change

...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
2 "devToolsPort": 19002, 2 "devToolsPort": 19002,
3 "expoServerPort": 19000, 3 "expoServerPort": 19000,
4 "packagerPort": 19001, 4 "packagerPort": 19001,
5 - "packagerPid": 18100, 5 + "packagerPid": 30352,
6 - "expoServerNgrokUrl": "https://ep-ukj.anonymous.searchguide.exp.direct", 6 + "expoServerNgrokUrl": "https://s4-47j.anonymous.searchguide.exp.direct",
7 - "packagerNgrokUrl": "https://packager.ep-ukj.anonymous.searchguide.exp.direct", 7 + "packagerNgrokUrl": "https://packager.s4-47j.anonymous.searchguide.exp.direct",
8 - "ngrokPid": 20760 8 + "ngrokPid": 19368
9 } 9 }
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
3 "lanType": "ip", 3 "lanType": "ip",
4 "dev": true, 4 "dev": true,
5 "minify": false, 5 "minify": false,
6 - "urlRandomness": "ep-ukj", 6 + "urlRandomness": "s4-47j",
7 "https": false 7 "https": false
8 } 8 }
......
1 import React from 'react'; 1 import React from 'react';
2 -import {View,Text,StyleSheet} from 'react-native' 2 +import Main from './components/Main/Main'
3 -import AppContainer from './components/AppContainer/AppContainer'; 3 +import { Provider,connect } from 'react-redux';
4 -import Loading from './components/Loading/Loading'; 4 +import Store from './reducers/Store';
5 5
6 -export default class App extends React.Component { 6 +const App = () => {
7 - constructor(props){
8 - super(props);
9 - this.state = {
10 - loading:false
11 - };
12 - }
13 -
14 - toggleLoading=()=>{
15 - this.setState({loading:true});
16 - }
17 -
18 - render(){
19 return ( 7 return (
20 - <> 8 + <Provider store={Store}>
21 - {this.state.loading ? <Loading/> : null} 9 + <Main />
22 - <AppContainer toggleLoading={this.toggleLoading}/> 10 + </Provider>
23 - </>
24 ) 11 )
25 - }
26 } 12 }
27 13
28 -const styles = StyleSheet.create({
29 - container: {
30 - flex: 1,
31 - justifyContent: 'center',
32 - },
33 -});
...\ No newline at end of file ...\ No newline at end of file
14 +export default App;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -6,13 +6,10 @@ import Home from '../Home/Home'; ...@@ -6,13 +6,10 @@ import Home from '../Home/Home';
6 import Rate from '../Rate/Rate'; 6 import Rate from '../Rate/Rate';
7 7
8 8
9 -const HomeScreen = (props) => (<Home toggleLoading={props.toggleLoading} />);
10 -const RateScreen = (props) => (<Rate toggleLoading={props.toggleLoading} />);
11 -
12 const AppTabNavigator = createMaterialTopTabNavigator ( 9 const AppTabNavigator = createMaterialTopTabNavigator (
13 { 10 {
14 - Home: HomeScreen, 11 + Home: Home,
15 - Rate: RateScreen 12 + Rate: Rate
16 }, 13 },
17 { 14 {
18 initialRouteName: 'Home', 15 initialRouteName: 'Home',
...@@ -43,5 +40,5 @@ const AppTabNavigator = createMaterialTopTabNavigator ( ...@@ -43,5 +40,5 @@ const AppTabNavigator = createMaterialTopTabNavigator (
43 }, 40 },
44 } 41 }
45 ); 42 );
46 -const AppContainer = createAppContainer(AppTabNavigator);
47 -export default AppContainer;
...\ No newline at end of file ...\ No newline at end of file
43 +const AppTabContainer = createAppContainer(AppTabNavigator);
44 +export default AppTabContainer;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,7 +19,7 @@ class Home extends React.Component { ...@@ -19,7 +19,7 @@ class Home extends React.Component {
19 render() { 19 render() {
20 return( 20 return(
21 <View style={{flex: 1, backgroundColor:'#eee', margin:0,padding:0}}> 21 <View style={{flex: 1, backgroundColor:'#eee', margin:0,padding:0}}>
22 - <SearchBar /> 22 + <SearchBar toggleLoading={this.props.toggleLoading}/>
23 <SearchCard title={'네이버- 지식인...인간사냥꾼 니달리를ㄴㄴㅁ'} content={'문도 가고 싶은 데로 간다!'} url={'https://www.naver.com'}/> 23 <SearchCard title={'네이버- 지식인...인간사냥꾼 니달리를ㄴㄴㅁ'} content={'문도 가고 싶은 데로 간다!'} url={'https://www.naver.com'}/>
24 </View> 24 </View>
25 25
......
1 +import React from 'react';
2 +import AppTabContainer from '../AppTabContainer/AppTabContainer';
3 +import Loading from '../Loading/Loading';
4 +import { connect } from 'react-redux';
5 +
6 +const Main = ({ isLoading, toggleLoading}) => {
7 + if ( isLoading ) {
8 + return(
9 + <>
10 + <Loading / >
11 + <AppTabContainer toggleLoading={toggleLoading}/>
12 + </>
13 + )
14 + }
15 + else{
16 + return (
17 + <AppTabContainer toggleLoading={toggleLoading}/>
18 + )
19 + }
20 +
21 +}
22 +
23 +
24 +const MainContainer = ({isLoading, toggleLoading}) => {
25 + return(<Main isLoading={isLoading} />)
26 +}
27 +
28 + const mapStateToProps = (state) => ({isLoading : state.ToggleLoading.isLoading})
29 +
30 + export default connect(mapStateToProps)(MainContainer);
...\ No newline at end of file ...\ No newline at end of file
1 import React from 'react'; 1 import React from 'react';
2 -import {View,ScrollView,Alert} from 'react-native'; 2 +import {View,Alert} from 'react-native';
3 -import { Searchbar, Divider, Text } from 'react-native-paper'; 3 +import { Searchbar } from 'react-native-paper';
4 -import Icon from 'react-native-vector-icons/FontAwesome';
5 -
6 4
7 export default class SearchBar extends React.Component { 5 export default class SearchBar extends React.Component {
8 constructor(props){ 6 constructor(props){
...@@ -17,7 +15,8 @@ export default class SearchBar extends React.Component { ...@@ -17,7 +15,8 @@ export default class SearchBar extends React.Component {
17 } 15 }
18 16
19 submit=()=>{ 17 submit=()=>{
20 - alert(this.state.query); 18 + this.props.toggleLoading;
19 + setInterval(()=>{this.props.toggleLoading},5);
21 this.setState({query:''}); 20 this.setState({query:''});
22 } 21 }
23 22
......
...@@ -5704,6 +5704,19 @@ ...@@ -5704,6 +5704,19 @@
5704 "react-deep-force-update": "^1.0.0" 5704 "react-deep-force-update": "^1.0.0"
5705 } 5705 }
5706 }, 5706 },
5707 + "react-redux": {
5708 + "version": "7.1.3",
5709 + "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.1.3.tgz",
5710 + "integrity": "sha512-uI1wca+ECG9RoVkWQFF4jDMqmaw0/qnvaSvOoL/GA4dNxf6LoV8sUAcNDvE5NWKs4hFpn0t6wswNQnY3f7HT3w==",
5711 + "requires": {
5712 + "@babel/runtime": "^7.5.5",
5713 + "hoist-non-react-statics": "^3.3.0",
5714 + "invariant": "^2.2.4",
5715 + "loose-envify": "^1.4.0",
5716 + "prop-types": "^15.7.2",
5717 + "react-is": "^16.9.0"
5718 + }
5719 + },
5707 "react-timer-mixin": { 5720 "react-timer-mixin": {
5708 "version": "0.13.4", 5721 "version": "0.13.4",
5709 "resolved": "https://registry.npmjs.org/react-timer-mixin/-/react-timer-mixin-0.13.4.tgz", 5722 "resolved": "https://registry.npmjs.org/react-timer-mixin/-/react-timer-mixin-0.13.4.tgz",
...@@ -5751,6 +5764,15 @@ ...@@ -5751,6 +5764,15 @@
5751 "util-deprecate": "~1.0.1" 5764 "util-deprecate": "~1.0.1"
5752 } 5765 }
5753 }, 5766 },
5767 + "redux": {
5768 + "version": "4.0.4",
5769 + "resolved": "https://registry.npmjs.org/redux/-/redux-4.0.4.tgz",
5770 + "integrity": "sha512-vKv4WdiJxOWKxK0yRoaK3Y4pxxB0ilzVx6dszU2W8wLxlb2yikRph4iV/ymtdJ6ZxpBLFbyrxklnT5yBbQSl3Q==",
5771 + "requires": {
5772 + "loose-envify": "^1.4.0",
5773 + "symbol-observable": "^1.2.0"
5774 + }
5775 + },
5754 "regenerate": { 5776 "regenerate": {
5755 "version": "1.4.0", 5777 "version": "1.4.0",
5756 "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", 5778 "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",
...@@ -6701,6 +6723,11 @@ ...@@ -6701,6 +6723,11 @@
6701 "has-flag": "^3.0.0" 6723 "has-flag": "^3.0.0"
6702 } 6724 }
6703 }, 6725 },
6726 + "symbol-observable": {
6727 + "version": "1.2.0",
6728 + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
6729 + "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ=="
6730 + },
6704 "temp": { 6731 "temp": {
6705 "version": "0.8.3", 6732 "version": "0.8.3",
6706 "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.3.tgz", 6733 "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.3.tgz",
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
24 "react-native-web": "^0.11.7", 24 "react-native-web": "^0.11.7",
25 "react-navigation": "^4.0.10", 25 "react-navigation": "^4.0.10",
26 "react-navigation-material-bottom-tabs": "^2.1.5", 26 "react-navigation-material-bottom-tabs": "^2.1.5",
27 - "react-navigation-tabs": "^2.5.6" 27 + "react-navigation-tabs": "^2.5.6",
28 + "react-redux": "^7.1.3",
29 + "redux": "^4.0.4"
28 }, 30 },
29 "devDependencies": { 31 "devDependencies": {
30 "babel-preset-expo": "^7.1.0", 32 "babel-preset-expo": "^7.1.0",
......
1 +import { createStore, combineReducers } from 'redux';
2 +import ToggleLoading from './ToggleLoading'
3 +
4 +const store = combineReducers({ ToggleLoading });
5 +
6 +export default createStore(store)
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +
3 +const TOGGLE_LOADING = 'ToggleLoading/TOGGLE';
4 +
5 +export const toggleLoading = () => ({ type: TOGGLE_LOADING,})
6 +
7 +const initialState = {
8 + isLoading: false,
9 +};
10 +
11 +export default ToggleLoading = (state = initialState, action) => {
12 + switch (action.type) {
13 + case TOGGLE_LOADING:
14 + return { isLoading: !initialState.isLoading };
15 + default:
16 + return state;
17 + }
18 +}
...\ No newline at end of file ...\ No newline at end of file