Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raise an error when lead to an incompatible type', () => {
if (Constants.platform && Constants.platform.ios) {
// $ExpectError
(Constants.platform.ios.buildNumber: number);
// $ExpectError
(Constants.platform.ios.platform: number);
// $ExpectError
(Constants.platform.ios.model: number);
// $ExpectError
(Constants.platform.ios.userInterfaceIdiom: number);
// $ExpectError
(Constants.platform.ios.systemVersion: number);
}
});
});
it('should have versionCode prop', () => {
if (Constants.platform && Constants.platform.android) {
(Constants.platform.android.versionCode: number);
// $ExpectError: check any
(Constants.platform.android.versionCode: boolean);
}
});
});
it('should have specific ios props', () => {
if (Constants.platform && Constants.platform.ios) {
(Constants.platform.ios.buildNumber: string);
(Constants.platform.ios.platform: string);
(Constants.platform.ios.model: string);
(Constants.platform.ios.userInterfaceIdiom:
| 'handset'
| 'tablet'
| 'unsupported');
(Constants.platform.ios.systemVersion: string);
}
});
it('should raise an error when lead to an incompatible type', () => {
export function getNotificationPlatform() {
return Constants.platform!.ios
? NotificationPlatform.IOS
: Constants.platform!.android
? NotificationPlatform.ANDROID
: NotificationPlatform.WEB;
}
import Constants from "expo-constants";
const hasiPhoneNotch =
Constants.platform!.ios &&
["iPhone X", "iPhone Xs", "iPhone Xs Max", "iPhone Xr"].includes(Constants.platform!.ios.model);
const notchHeight = Constants.statusBarHeight + (hasiPhoneNotch ? 0 : 0);
export default notchHeight;
export const bottomMargin = hasiPhoneNotch ? 28 : 0;
import Constants from "expo-constants";
const constants = {
headerOffset: 80,
buildNumber: Constants.manifest.ios.buildNumber,
version: Constants.manifest.version,
systemVersion: Constants.platform.ios.systemVersion,
model: Constants.platform.ios.model,
spacing: {
tiny: 2,
small: 4,
medium: 8,
large: 16,
mlarge: 20,
xlarge: 24,
xxlarge: 32
}
};
const feedbackTemplate = `
---
Build: ${constants.buildNumber}
getPermissionAsync = async () => {
if (Constants.platform.ios) {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL)
if (status !== 'granted') {
alert('Sorry, we need camera roll permissions to make this work!')
}
}
}
public render() {
return ;
}
}
function NotificationImage({ width, height }: { width: number; height: number }) {
const image = Constants.platform!.ios ? IMAGES.ios : IMAGES.android;
const ratio = image.height / image.width;
const renderWidth = Math.min(width - 40, image.width);
const renderMargin = (width - renderWidth) / 2;
const renderHeight = renderWidth * ratio;
const style = {
position: "absolute" as "absolute",
width: renderWidth,
left: 0,
marginLeft: renderMargin,
marginRight: renderMargin,
top: height * 0.6,
height: renderHeight
};
import { Platform } from 'react-native';
import Constants from 'expo-constants';
import packageInfo from '../package';
const os = Platform.OS === 'ios' ? 'iOS' : 'Android';
export const isiOS = Platform.OS === 'ios';
export const isAndroid = Platform.OS === 'android';
export default {
os,
browser: 'App',
environment: `App ${process.env.NODE_ENV === 'development' ? '开发版' : packageInfo.version} on ${os} ${isiOS ? Constants.platform.ios.systemVersion : Constants.systemVersion} ${isiOS ? Constants.platform.ios.model : ''}`,
};