Docsity
Trusted Seller

React native - dispensa pratica, Dispense di Sviluppo di Applicazioni Web

Toggle sidebar
bg1
Applicare dello style 1
Applicare dello style
App.js
import React from "react";
import Post from "./FacebookPost";
function App() {
return (
<div>
<h1> Home </h1>
<Post author="Andrea" description="Ciao, questo è il mio post" />
<Post author="Billy" description="Hello" />
</div>
);
}
export default App;
FacebookPost.js
import React from "react";
import "./App.css";
function Post(props) {
return (
<div className=".Post">
<h2>{props.author}</h2>
<h4>{props.description}</h4>
<button> Like </button>
</div>
);
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica React native - dispensa pratica e più Dispense in PDF di Sviluppo di Applicazioni Web solo su Docsity!

Applicare dello style 1

Applicare dello style

App.js

import React from "react"; import Post from "./FacebookPost"; function App() { return (

Home

); } export default App;

FacebookPost.js

import React from "react"; import "./App.css"; function Post(props) { return (

{props.author} {props.description} Like

);

Applicare dello style 2 } export default Post;

App.css

.Post{ border: 1px solid black; display: flex; justify-content: center; flex-direction: column; width: 300px; }

Index.css

body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; background-color: lightblue; } code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; }

Bottone che cambia colore cliccandolo 2 //TouchableOpacity = bottone con funzione onPress

Premi

); } } //stile del bottone const styles = StyleSheet.create({ button: { backgroundColor: "blue", }, text: { fontSize: 30, fontWeight: "bold", }, });

Bottone con funzione 1

Bottone con funzione

App.js

import React from "react"; import Stampa from "./Stampa"; function App() { return (

Esempio React

); } export default App;

Stampa.js

import React from "react"; function Stampa() { const stampa = () => { console.log("hello"); }; return Cliccami ; } export default Stampa;

Contatore con hooks 1

Contatore con hooks

App.js

import React, { useState } from "react"; import "./App.css"; function App() { const [count, setCount] = useState(0); const increment = () => { setCount(count + 1); }; return (

counter : {count} Aumenta

); } export default App;

App.css

.Container{ display: flex; justify-content: center; align-items: center; height : 100vh; }

Contatore con hooks 2

Index.css

body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; background-color: lightblue; } code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; }

Contatore con state 2 justify-content: center; align-items: center; height : 100vh; }

Index.css

body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; background-color: lightblue; } code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; }

ESERCIZI REACT NATIVE INSTAGRAM 1 App 1 HomeScreen 1 SEARCH BAR 10 selected 10 SearchBarFilter 11 SearchBar 14 ListHorizontal 14 index 16 Heart 16 FetchLike 17 Fetch 19 App 21 ToDoList 22 Card 25 useSerieList 27 SearchBar 28 TIMER 30 App 30 INSTAGRAM App import React from 'react'; import { View } from 'react-native'; import HomeScreen from './src/HomeScreen'; const App = () => { return (

); }; export default App;

{story.name}

))}

); }; // Componente per i post const Post = ({ post }) => { const [likes, setLikes] = useState(post.likes); const [isLiked, setIsLiked] = useState(false); const [isBookmarked, setIsBookmarked] = useState(false); const [showComments, setShowComments] = useState(false); const [showFullDescription, setShowFullDescription] = useState(false); const handleBookmark = () => { setIsBookmarked(!isBookmarked); }; const handleLike = () => { setIsLiked(!isLiked); setLikes(isLiked? likes - 1 : likes + 1); }; const toggleComments = () => { setShowComments(!showComments); }; const toggleDescription = () => { setShowFullDescription(!showFullDescription); }; const numbersOfCharacter = post.description.length; const hasEnoughDescriptionLines = numbersOfCharacter >= 100; return (

{likes}

{post.nickname}: {post.description}

{hasEnoughDescriptionLines && !showFullDescription && (

Mostra di più

)} {showFullDescription && (

Mostra di meno

)} {showComments? ( <>

{post.comments.map((comment, index) => (

{comment.user} {comment.text}

))}

Nascondi commenti

const postData = [ { image: 'https://i.pinimg.com/originals/5e/b2/7c/5eb27c1003b89cbeda603d46a59c6b3e.jpg', description: 'Lorem ipsum dolor sitaunttur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum clari, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.', likes: 123, comments: [ { user: 'User1', text: 'Primo commento', image: 'https://th.bing.com/th/id/OIP.7SRvPLTTuqKLzM04PaXsfwHaJQ?pid=ImgDet&rs=1' }, { user: 'User2', text: 'Secondo commento', image: 'https://th.bing.com/th/id/OIP.j5J3h8GOK7b4LkD_Go_NxgHaJg?pid=ImgDet&rs=1' }, { user: 'User3', text: 'Terzo commento', image: 'https://th.bing.com/th/id/OIP.iEG7If6ckzQaMAv2tPP6-wHaHa?pid=ImgDet&w=768&h=768&r s=1' }, ], nickname: 'Nickname1', userImage: 'https://th.bing.com/th/id/OIP.8t2B_cCHUZpjRUnTD03SYAHaEI?pid=ImgDet&rs=1', }, { image: 'https://i.pinimg.com/originals/90/71/3e/90713e127abc9b67f7c1106a899ede93.jpg', description: 'Questo è il secondo post', likes: 456, comments: [ { user: 'User4', text: 'Commento post 2-1', image: 'https://example.com/user4.jpg' }, { user: 'User5', text: 'Commento post 2-2', image: 'https://example.com/user5.jpg' }, ], nickname: 'Nickname2', userImage: 'https://th.bing.com/th/id/OIP.dUngPLt8xS2GSkAmCwIQmQHaEI?pid=ImgDet&rs=1', }, ]; return (

{postData.map((post, index) => (

))}

); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#FFF', paddingVertical: 10, }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 10, marginBottom: 10, }, headerLeft: { flexDirection: 'row', alignItems: 'center', }, headerRight: { paddingRight: 5, }, headerText: { fontSize: 20, fontWeight: 'bold', textAlign: 'center', flex: 1, }, icon: { padding: 5, }, storiesContainer: { flexDirection: 'row', paddingVertical: 10, borderBottomWidth: 1, borderBottomColor: '#EEE', marginBottom: 10, }, story: { alignItems: 'center', marginRight: 15, }, storyImage: { width: 60,

commentImage: { width: 30, height: 30, borderRadius: 15, }, commentContent: { marginLeft: 10, }, commentUser: { fontWeight: 'bold', }, commentText: { color: '#888', }, hideComments: { color: 'blue', marginBottom: 10, }, viewComments: { color: 'blue', marginBottom: 10, }, viewMoreButton: { color: 'black', marginBottom: 10, fontWeight: 'bold', // Aggiunta della proprietà fontWeight }, bottomBar: { height: 50, backgroundColor: '#FFF', borderTopWidth: 1, borderTopColor: '#EEE', flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center', marginTop: 10, }, icon: { padding: 5, }, bookmarks: { flexDirection: 'row', justifyContent: 'space-between', paddingHorizontal: 10, marginBottom: 10, }, postHeader: {

flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 10, marginBottom: 10, }, profileContainer: { flexDirection: 'row', alignItems: 'center', }, profileImageContainer: { width: 30, height: 30, borderRadius: 15, overflow: 'hidden', marginRight: 10, }, profileImage: { width: '100%', height: '100%', }, profileName: { fontWeight: 'bold', }, }); export default HomeScreen; SEARCH BAR selected import React, { useState } from "react"; import { FlatList, SafeAreaView, StatusBar, StyleSheet, Text, TouchableOpacity } from "react-native"; const DATA = [ { id: "1", title: "First Item", }, { id: "2", title: "Second Item", },