我正在尝试检测这个应用程序是运行在安卓还是androidTV上,因为我问here的问题,我不能使用react-native's platform api。
有没有其他的包可以让我这样做呢?或者我可以用javascript自己写?
发布于 2021-07-04 22:50:50
您可以从react-native-device-info
https://github.com/react-native-device-info/react-native-device-info#getDeviceType使用getDeviceType
helper
import React from 'react';
import { View, Text } from 'react-native';
import { getDeviceType } from 'react-native-device-info';
const deviceType = getDeviceType();
const App = () => {
return (
<View>
<Text>{deviceType}</Text>
</View>
);
};
export default App;
发布于 2021-07-05 05:54:17
我不知道这是否会解决您的特定用例,但您可以通过在文件名中指定每个平台的特定文件:
index.android.js
index.ios.js
React native将根据平台选择要使用的文件。
发布于 2021-08-05 13:45:47
尝试来自React Native的平台模块
import { Platform } from "react-native"
isTV === Platform.constants.uiMode === "tv"
https://stackoverflow.com/questions/68245286
复制相似问题