_5_Root.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React ,{useState, useRef, useEffect} from 'react';
  2. // import Tab from '../navigation/TabNavigator';
  3. import C from 'rn-class';
  4. import Main from './_6_Main';
  5. import List from './_7_List';
  6. import TabBar from '../components/TabBar';
  7. import Player from "../components/Player";
  8. //import Player from "./PlayerGesture";
  9. import { PlayerConextProvider } from '../components/PlayerReducer'
  10. C.addColor("#d7d7d7", "color-listbg");
  11. import {BTNS_ORG as BTNS} from '../data/dummy';
  12. import { BackHandler } from 'react-native';
  13. const tabPosition = {x:0, y:0, w:0, h:0};
  14. export default (props)=>{
  15. const [ sel_idx, setsel_Idx ] = useState(-1);
  16. const [ targetIdx, setTargetIdx ] = useState(-1);
  17. const [ bPlay, setbPlay] = useState(false);
  18. const [ curPlayInfo, setCurPlayInfo] = useState({});
  19. const onTabPress = (tIdx, i)=>{
  20. setsel_Idx(i);
  21. setTargetIdx(tIdx);
  22. setbPlay(false);
  23. }
  24. const startPlay = (playerData)=>{
  25. setbPlay(true);
  26. setCurPlayInfo(playerData);
  27. }
  28. let Page;
  29. if(sel_idx == -1){
  30. Page = Main;
  31. }else{
  32. Page = List;
  33. }
  34. useEffect(()=>{
  35. BackHandler.addEventListener(
  36. 'hardwareBackPress',
  37. ()=>{
  38. // 소형화 로직
  39. return props.navigation.isFocused();
  40. }
  41. )
  42. return () => {
  43. console.log('will unmount');
  44. }
  45. },[]);
  46. const setTabPosition = (data) => {
  47. tabPosition.x = data.x;
  48. tabPosition.y = data.y;
  49. tabPosition.w = data.w;
  50. tabPosition.h = data.h;
  51. }
  52. return (
  53. <C.View cls="flx1 bgc-color-white">
  54. <C.Comp.Header {...props}/>
  55. <Page {...props} Pages={sel_idx == -1 ? {} : BTNS[targetIdx][sel_idx]} startPlay={startPlay} bPlay={bPlay}/>
  56. <PlayerConextProvider>
  57. {bPlay ? <Player playerData={curPlayInfo} tabPosition={tabPosition} closePlayer={()=>setbPlay(false)}/> : null}
  58. </PlayerConextProvider>
  59. <TabBar setTabPosition={setTabPosition} onTabPress={onTabPress} BTNS={BTNS}/>
  60. </C.View>
  61. )
  62. }