|
| 1 | +# React Native JS |
| 2 | + |
| 3 | +Tags: JS, React |
| 4 | + |
| 5 | +## Nov 1 |
| 6 | + |
| 7 | +- I just got the course and I am going to start the course |
| 8 | +- I am going to document how I installed everything and small notices |
| 9 | + |
| 10 | +## Nov 2 |
| 11 | + |
| 12 | +- Yesterday I got android studio working |
| 13 | +- And Now I am starting the main part which teaches React Native 🙂 |
| 14 | +- If any updated I will ad |
| 15 | + |
| 16 | +```jsx |
| 17 | +// The below will convert the number of lines to 1 |
| 18 | +<Text numberOfLines={1} onPress={handlePress}> |
| 19 | + Open up App.js to start working on your app! - A really really long text |
| 20 | + I want to make this really long |
| 21 | +</Text> |
| 22 | + |
| 23 | +// Add Image Local |
| 24 | +<Image source={require("./assets/icon.png")} width={300} height={300} /> |
| 25 | + <TouchableHighlight onLongPress={handlePress}> |
| 26 | + <Image |
| 27 | + fadeDuration={1000} |
| 28 | + source={{ |
| 29 | + uri: "https://i.picsum.photos/id/594/200/300.jpg?hmac=kcNk6N4hJqRhoKUJ8ZeFWLMVV-2_Z5hLfxCFEyrsAx4", |
| 30 | + width: 300, |
| 31 | + height: 300, |
| 32 | + }} |
| 33 | + /> |
| 34 | + <View style={{width: 300, height: 300, backgroundColor:"gray"}}></View> |
| 35 | + </TouchableHighlight> |
| 36 | + |
| 37 | +// Button |
| 38 | +<Button |
| 39 | + style={{ color: "black", backgroundColor: "white" }} |
| 40 | + title="Click Me" |
| 41 | + onPress={() => console.log("hgt")} |
| 42 | + |
| 43 | + /> |
| 44 | +// Allert |
| 45 | +onPress={() => Alert.alert("My title","Message",[ |
| 46 | + { |
| 47 | + text:"Yes", |
| 48 | + style: { color: "black",backgroundColor: "white"}, |
| 49 | + onPress : () => alert("YES") |
| 50 | + }, |
| 51 | + { |
| 52 | + text:"No", |
| 53 | + style: { color: "black",backgroundColor: "white"}, |
| 54 | + onPress : () => alert("NO") |
| 55 | + } |
| 56 | + ])} |
| 57 | + |
| 58 | +// Specific |
| 59 | + |
| 60 | +paddingTop : Platform.OS === "android" ? 10 : 0 |
| 61 | + |
| 62 | +// Demensions |
| 63 | +console.log(Dimensions.get('screen')) |
| 64 | + |
| 65 | +// Oreitation |
| 66 | +const { landscape } = useDeviceOrientation(); |
| 67 | +console.log(useDimensions()); |
| 68 | + console.log(useDeviceOrientation()); |
| 69 | + |
| 70 | +height: landscape ? "50%" : "30%", |
| 71 | + |
| 72 | +// Flex |
| 73 | + |
| 74 | +<View |
| 75 | + style={{ |
| 76 | + backgroundColor: "#ff", |
| 77 | + flex: 1, |
| 78 | + flexDirection: "row", |
| 79 | + }} |
| 80 | + > |
| 81 | + <View |
| 82 | + style={{ backgroundColor: "dodgerblue", width: 100, height: 100 }} |
| 83 | + /> |
| 84 | + <View style={{ backgroundColor: "gold", width: 100, height: 100 }} /> |
| 85 | + <View style={{ backgroundColor: "tomato", width: 100, height: 100 }} /> |
| 86 | + </View> |
| 87 | + |
| 88 | +// Flex |
| 89 | +flexDirection: "row", // hoezontal |
| 90 | + justifyContent:"center", // man |
| 91 | + alignItems: "center" // secondry |
| 92 | + |
| 93 | +// Flex |
| 94 | + |
| 95 | +alignContent: "center", // Center the items |
| 96 | + flexWrap: "wrap", // Go to new line+ |
| 97 | + |
| 98 | +// Shortcut |
| 99 | +# rfs |
| 100 | +# rnss |
| 101 | + |
| 102 | +// Border |
| 103 | + |
| 104 | +<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> |
| 105 | + <View |
| 106 | + style={{ |
| 107 | + backgroundColor: "dodgerblue", |
| 108 | + width: 100, |
| 109 | + height: 100, |
| 110 | + borderWidth: 10, |
| 111 | + borderColor: "royalblue", |
| 112 | + borderRadius: 10, |
| 113 | + }} |
| 114 | + ></View> |
| 115 | + </View> |
| 116 | + |
| 117 | +// Shadows |
| 118 | + |
| 119 | +<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> |
| 120 | + <View |
| 121 | + style={{ |
| 122 | + backgroundColor: "dodgerblue", |
| 123 | + width: 100, |
| 124 | + height: 100, |
| 125 | + shadowColor: "grey", |
| 126 | + shadowOffset: { height: 10, width: 10 }, |
| 127 | + shadowOpacity: 1, |
| 128 | + shadowRadius: 10, |
| 129 | + elevation: 50, |
| 130 | + }} |
| 131 | + ></View> |
| 132 | + </View> |
| 133 | + |
| 134 | +// Difference betweening margin and padding |
| 135 | +// padding = the space inside the div |
| 136 | +// margin = the space around the div |
| 137 | + |
| 138 | +<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> |
| 139 | + <View |
| 140 | + style={{ |
| 141 | + backgroundColor: "dodgerblue", |
| 142 | + width: 100, |
| 143 | + height: 100, |
| 144 | + padding: 20, |
| 145 | + paddingHorizontal: 10, |
| 146 | + paddingLeft: 30, |
| 147 | + }} |
| 148 | + > |
| 149 | + <View styles={{ backgroundColor: "gold", width: 50, height: 50 }}> |
| 150 | + <Text></Text> |
| 151 | + </View> |
| 152 | + </View> |
| 153 | + </View> |
| 154 | + |
| 155 | +// Text Custom |
| 156 | +fontFamily: "Roboto", |
| 157 | + fontStyle: "italic", |
| 158 | + fontWeight: "600", |
| 159 | + color: "tomato", |
| 160 | + textTransform: "uppercase", |
| 161 | + textAlign: "center", |
| 162 | + |
| 163 | +// Create cust custom component |
| 164 | + |
| 165 | +import React from "react"; |
| 166 | +import { Text, StyleSheet, Platform } from "react-native"; |
| 167 | +function AppText({ children }) { |
| 168 | + return <Text style={styles.text}>{children}</Text>; |
| 169 | +} |
| 170 | +const styles = StyleSheet.create({ |
| 171 | + text: { |
| 172 | + fontSize: 18, |
| 173 | + fontFamily: Platform.OS === "android" ? "Roboto" : "Avernir", |
| 174 | + }, |
| 175 | +}); |
| 176 | +export default AppText; |
| 177 | + |
| 178 | +// PlatForm |
| 179 | +...Platform.select({ |
| 180 | + ios: { |
| 181 | + fontSize: 20, |
| 182 | + }, |
| 183 | + android: { |
| 184 | + fontSize: 50, |
| 185 | + }, |
| 186 | + }) |
| 187 | + |
| 188 | +// Platform |
| 189 | +App.ios.js |
| 190 | +App.android.js |
| 191 | + |
| 192 | +// Clean |
| 193 | + |
| 194 | +// /app/componentns/AppText/AppText.js and styple.js |
| 195 | + |
| 196 | +// Swithc |
| 197 | + |
| 198 | +<Switch |
| 199 | + value={isNew} |
| 200 | + onValueChange={(newValue) => { |
| 201 | + setIsNew(newValue); |
| 202 | + }} |
| 203 | + /> |
| 204 | +``` |
0 commit comments