




























































































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





























































































Applicare dello style 1
import React from "react"; import Post from "./FacebookPost"; function App() { return (
Home
); } export default App;
import React from "react"; import "./App.css"; function Post(props) { return (
{props.author} {props.description} Like
);
Applicare dello style 2 } export default Post;
.Post{ border: 1px solid black; display: flex; justify-content: center; flex-direction: column; width: 300px; }
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
import React from "react"; import Stampa from "./Stampa"; function App() { return (
Esempio React
); } export default App;
import React from "react"; function Stampa() { const stampa = () => { console.log("hello"); }; return Cliccami ; } export default Stampa;
Contatore con hooks 1
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;
.Container{ display: flex; justify-content: center; align-items: center; height : 100vh; }
Contatore con hooks 2
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; }
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", },