npm install -g expo-cli
expo init myApp
React Native Tools: 可以讓我們在 vscode 裡面 debug 我們的 App
android emulator:
這樣就建立完成一個 android emulator
npm start
接下來就會在 android emulator 上下載並執行我們的
程式
npm start
(搖晃手機可以開啟 developer menu)
<View/>
: 跟 div 差不多
<SafeAreaView/>
: 排除掉會被手機擋住的地方
<Text/>
<Text numberOfLines={1} onPress={handlePress}>Hello World!</Text>
Image
// 使用內部圖案
<Image source={require('./assets/icon.png')}/>
// 使用外部圖案 - soucre 接收物件
<Image
fadeDuration={100} // fade 100ms
blurRadius={5}
source={{
width: 200,
height: 300,
uri: "https://picsum.photos/200/300",
}}
/>
<TouchableWithoutFeedback/>
, <TouchableOpacity/>
, <TouchableHighlight/>
: 讓圖片能夠點擊
<TouchableHighlight onPress={() => console.log("Press!")}>
<Image
source={{
width: 200,
height: 300,
uri: "https://picsum.photos/200/300",
}}
/>
</TouchableHighlight>
<Button/>
<Button
color="orange"
title="Click Me!"
onPress={() => console.log("Clicked")}
/>
Alert
: (function) 跳出詢問視窗
Alert.alert(
"Alert title",
"message",
[
// Alert 中的選項
{ text: "Yes", onPress: () => console.log("Yes") },
{ text: "No", onPress: () => console.log("No") },
]
)
Platform
: (function) 偵測os
alert("This Platform's OS is : " + Platform.OS)
獲得裝置方向:
// 1. Dimentions.get("screen")
console.log(Dimentios.get("screen"))
// 2. use hooks (npm install @react-native-community/hooks)
import {
useDimensions,
useDeviceOrientation,
} from "@react-native-community/hooks";
// get orientation from hooks
const orientation = useDeviceOrientation();
const dimensions = useDimensions();
flex
in style: flex: 1
代表全部, 0.5 代表一半
— Mar 28, 2022
Made with ❤ and at Taiwan.