oktatas:telefon:react_native:nezetek_kapcsolasa
Különbségek
A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
Előző változat mindkét oldalonElőző változat | |||
oktatas:telefon:react_native:nezetek_kapcsolasa [2022/01/01 01:01] – [Osztály] admin | oktatas:telefon:react_native:nezetek_kapcsolasa [2022/01/01 09:10] (aktuális) – admin | ||
---|---|---|---|
Sor 2: | Sor 2: | ||
====== Nézetek kapcsolása ====== | ====== Nézetek kapcsolása ====== | ||
- | + | | |
- | | + | * [[oktatas:telefon:react_native:nezetek_kapcsolasa:Függvénnyel]] |
- | * Copyright (c) Sallai András, 2021 | + | |
- | * Licenc: | + | |
- | * Web: https://szit.hu | + | |
- | + | ||
- | ===== Osztállyal ===== | + | |
- | + | ||
- | ==== App.js ==== | + | |
- | + | ||
- | + | ||
- | <code javascript App.js> | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Button, Text } from ' | + | |
- | + | ||
- | import ComponentA from ' | + | |
- | import ComponentB from ' | + | |
- | import ComponentC from ' | + | |
- | + | ||
- | export default class App extends Component { | + | |
- | + | ||
- | state = { | + | |
- | selectedTab: '' | + | |
- | } | + | |
- | + | ||
- | setTab = (tab) => { | + | |
- | this.setState({selectedTab: tab}); | + | |
- | | + | |
- | selectTab = () => { | + | |
- | + | ||
- | switch(this.state.selectedTab) { | + | |
- | case ' | + | |
- | return < | + | |
- | case ' | + | |
- | return < | + | |
- | case ' | + | |
- | return < | + | |
- | default: | + | |
- | return | + | |
- | } | + | |
- | } | + | |
- | render() { | + | |
- | return ( | + | |
- | + | ||
- | <View style={styles.container}> | + | |
- | <View style={styles.buttonBox}> | + | |
- | <Button onPress={() => this.setTab(' | + | |
- | <Button onPress={() => this.setTab(' | + | |
- | color=' | + | |
- | /> | + | |
- | <Button onPress={() => this.setTab(' | + | |
- | <View style={styles.component}> | + | |
- | {this.selectTab()} | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | buttonBox: { | + | |
- | flex: 1, | + | |
- | width: ' | + | |
- | }, | + | |
- | component: { | + | |
- | flex: 1, | + | |
- | } | + | |
- | }); | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Komponensek ==== | + | |
- | + | ||
- | <code javascript components/ | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class ComponentA extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | <code javascript components/ | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class ComponentB extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | <code javascript components/ | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class ComponentC extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | ===== Függvényekkel ===== | + | |
- | + | ||
- | <code javascript App.js> | + | |
- | import { StyleSheet, Text, View, Button } from ' | + | |
- | import { useState } from ' | + | |
- | + | ||
- | import Compa from ' | + | |
- | import Compb from ' | + | |
- | import Compc from ' | + | |
- | + | ||
- | export default function App() { | + | |
- | const [selectedTab, | + | |
- | + | ||
- | let setTab = (tab) => { | + | |
- | setSelectedTab(tab); | + | |
- | } | + | |
- | let selectTab = () => { | + | |
- | | + | |
- | case ' | + | |
- | return <Compa /> | + | |
- | case ' | + | |
- | return <Compb /> | + | |
- | case ' | + | |
- | return <Compc /> | + | |
- | default: | + | |
- | return | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | <View style={styles.buttonBox}> | + | |
- | <Button onPress={() => setTab(' | + | |
- | <Button onPress={() => setTab(' | + | |
- | color=' | + | |
- | /> | + | |
- | <Button onPress={() => setTab(' | + | |
- | <View style={styles.component}> | + | |
- | {selectTab()} | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | buttonBox: { | + | |
- | flex: 1, | + | |
- | width: ' | + | |
- | }, | + | |
- | component: { | + | |
- | flex: 1, | + | |
- | } | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | <code javascript compa.js> | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class Compa extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | <code javascript compa.js> | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class Compb extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | <code javascript compa.js> | + | |
- | import React, { Component} from ' | + | |
- | import { View, StyleSheet, Text } from ' | + | |
- | + | ||
- | export default class Compc extends Component { | + | |
- | render() { | + | |
- | return ( | + | |
- | <View style={styles.container}> | + | |
- | < | + | |
- | </ | + | |
- | ); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | const styles = StyleSheet.create({ | + | |
- | container: { | + | |
- | flex: 1, | + | |
- | backgroundColor: | + | |
- | alignItems: ' | + | |
- | justifyContent: | + | |
- | }, | + | |
- | }); | + | |
- | </ | + |
oktatas/telefon/react_native/nezetek_kapcsolasa.1640995288.txt.gz · Utolsó módosítás: 2022/01/01 01:01 szerkesztette: admin