Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // App.js
  2. import React from 'react';
  3. import { Root, View } from '@vkontakte/vkui';
  4. import '@vkontakte/vkui/dist/vkui.css';
  5.  
  6. import Home from './panels/Home';
  7. import Persik from './panels/Persik';
  8.  
  9. class App extends React.Component {
  10.     constructor(props) {
  11.         super(props);
  12.  
  13.         this.state = {
  14.             activeView: 'home',
  15.             homePanel: 'main',
  16.             addPanel: 'main'
  17.         };
  18.  
  19.         this.go = this.go.bind(this);
  20.         this.changeView = this.changeView.bind(this);
  21.     }
  22.  
  23.     go(panel) {
  24.         let name = `${this.state.activeView}Panel`;
  25.         this.setState({ [name]: panel });
  26.     }
  27.     changeView(activeView) {
  28.         this.setState({ activeView })
  29.     }
  30.  
  31.     render() {
  32.         return (
  33.             <Root activeView={this.state.activeView}>
  34.                 <View activePanel={this.state.homePanel} id="home">
  35.                     <Home id="main" go={this.go} changeView={this.changeView} />
  36.                     <Persik id="persik" go={this.go} />
  37.                 </View>
  38.                 <View activePanel={this.state.addPanel} id="add">
  39.                     <Persik id="main" go={this.go} changeView={this.changeView} />
  40.                 </View>
  41.             </Root>
  42.         );
  43.     }
  44. }
  45.  
  46. // Home.js
  47. import React from 'react';
  48. import PropTypes from 'prop-types';
  49. import { Panel, ListItem, Button, Group, Div, Avatar, PanelHeader } from '@vkontakte/vkui';
  50.  
  51. const Home = ({ id, go, fetchedUser, changeView }) => (
  52.     <Panel id={id}>
  53.         <PanelHeader>Example</PanelHeader>
  54.         <Group title="Navigation Example">
  55.             <Div>
  56.                 <Button size="xl" level="2" onClick={() => go('persik')}>
  57.                     Show me the Persik, please
  58.                 </Button>
  59.                 <Button size="xl" level="2" onClick={() => changeView('add')}>
  60.                     Show me the Persik, please
  61.                 </Button>
  62.             </Div>
  63.         </Group>
  64.     </Panel>
  65. );
  66.  
  67. Home.propTypes = {
  68.     id: PropTypes.string.isRequired,
  69.     go: PropTypes.func.isRequired,
  70.     fetchedUser: PropTypes.shape({
  71.         photo_200: PropTypes.string,
  72.         first_name: PropTypes.string,
  73.         last_name: PropTypes.string,
  74.         city: PropTypes.shape({
  75.             title: PropTypes.string,
  76.         }),
  77.     }),
  78. };
  79.  
  80. export default Home;
  81.  
  82. // Persik.js
  83. import React from 'react';
  84. import PropTypes from 'prop-types';
  85. import {Panel, PanelHeader, HeaderButton, platform, IOS} from '@vkontakte/vkui';
  86. import persik from '../img/persik.png';
  87. import './Persik.css';
  88. import Icon28ChevronBack from '@vkontakte/icons/dist/28/chevron_back';
  89. import Icon24Back from '@vkontakte/icons/dist/24/back';
  90.  
  91. const osname = platform();
  92.  
  93. const Persik = props => (
  94.     <Panel id={props.id}>
  95.         <PanelHeader
  96.             left={<HeaderButton onClick={() => props.go('main')}>
  97.                 {osname === IOS ? <Icon28ChevronBack/> : <Icon24Back/>}
  98.             </HeaderButton>}
  99.         >
  100.             Persik
  101.         </PanelHeader>
  102.         <img className="Persik" src={persik} alt="Persik The Cat" onClick={() => props.changeView('home')} />
  103.     </Panel>
  104. );
  105.  
  106. Persik.propTypes = {
  107.     id: PropTypes.string.isRequired,
  108.     go: PropTypes.func.isRequired,
  109. };
  110.  
  111. export default Persik;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement