1. Text 的絕對居中 Android中顯示時會有預設的padding保留,導致垂直居中會有誤差 //不寫下麵兩個,Android系統上文字會偏下* includeFontPadding: false, textAlignVertical: "center", Text省略號顯示 <Text n ...
1. Text 的絕對居中
Android中顯示時會有預設的padding保留,導致垂直居中會有誤差
//不寫下麵兩個,Android系統上文字會偏下*
includeFontPadding: false,
textAlignVertical: "center",
Text省略號顯示
<Text numberOfLines={2} ellipsizeMode={'tail'} >文字文字文字文字文字文字</Text>
2. 使用第三方字體
-
字體文件放在
assets/fonts/
-
// 項目根目錄控制台輸入 react-native link
-
fontFamily: *****
3. 適配大小
- 設計稿元素寬度(px) / 設計稿總寬度(px) = 元素的寬度(dp) / 屏幕的總寬度(dp)
4. 配置絕對路徑
文件名不支持下劃線
-
npm install babel-plugin-module-resolver
-
babel.config.js
中添加如下代碼plugins: [ [ "babel-plugin-module-resolver", { root: ['./'], // 從哪個文件開始設置絕對路徑 alias: { '@/assets': './assets', '@/components': './components', "@/pages": './pages', "@/utils": './utils', "@/reducers": './reducers', }, }, ] ]
-
tsconfig.json
中添加配置"baseUrl": "./", /* Base directory to resolve non-absolute module names. */ "paths": { "@/img/*": ["img/*"], "@/components/*": ["components/*"], "@/pages/*": ["pages/*"], "@/reducers/*": ["reducers/*"], "@/utils/*": ["utils/*"], },
5. 關閉控制台警告
//關閉全部黃色警告 在product環境預設是關閉的
import { LogBox } from 'react-native';
LogBox.ignoreAllLogs(true)
6. 介面調試
mock的介面必須在開始DeBug模式下才能生效否則會報錯
7. 陰影相容
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
8. input點擊空白處自動收起
將input放在ScrollView內
9. 藍牙組件Android
// AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION " />
10. Android
READ CALENDAR 閱讀日曆
WRITE CALENDAR 寫日曆
CAMERA 相機
READ CONTACTS 閱讀聯繫人
WRITE CONTACTS
GET ACCOUNTS
ACCESS FINE LOCATION
ACCESS COARSE LOCATION
ACCESS BACKGROUND LOCATION
RECORD AUDIO
READ PHONE STATE
CALL PHONE
READ CALL LOG
WRITE CALL LOG
ADD VOICEMAIL
USE SIP
PROCESS OUTGOING CALLS
BODY SENSORS
SEND SMS
RECEIVE SMS
READ SMS
RECEIVE WAP PUSH
RECEIVE MMS
READ EXTERNAL STORAGE
WRITE EXTERNAL STORAG
BLUETOOTH CONNECT:
BLUETOOTH SCAN
BLUETOOTH ADVERTISE
ACCESS MEDIA LOCATION
ACCEPT HANDOVER
ACTIVITY RECOGNITION:
ANSWER PHONE CALLS:
READ PHONE NUMBERS:
UWB RANGING
Android真機調試
// D鍵
adb shell input keyevent 82
1、手機和PC在同一網段的情況下
把手機usb和連接線和電腦端連接起來,輸入下麵命令
1)、adb tcpip 5555
2) 、adb shell ifconfig 查看手機網路IP
3)、在電腦上ping 手機網路ip
4) 、 adb connect ip (Android 設備ip)