Skip to content

Commit

Permalink
Merge pull request #320 from SurpassRabbit/master
Browse files Browse the repository at this point in the history
1. 适配iPhone XS等新机型
  • Loading branch information
rilyu authored Nov 27, 2018
2 parents 8c371bc + 455ed9e commit d7bb0b2
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions themes/Theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,46 @@ import ThemeViolet from './ThemeViolet';
// See https://mydevice.io/devices/ for device dimensions
const X_WIDTH = 375;
const X_HEIGHT = 812;
const XSMAX_WIDTH = 414;
const XSMAX_HEIGHT = 896;
const PAD_WIDTH = 768;
const PAD_HEIGHT = 1024;

const {width: D_WIDTH, height: D_HEIGHT} = Dimensions.get('window');

const { PlatformConstants = {} } = NativeModules;
const { minor = 0 } = PlatformConstants.reactNativeVersion || {};

const isPad = D_WIDTH >= PAD_WIDTH && D_HEIGHT >= PAD_WIDTH;

const isIPhoneX = (() => {
if (Platform.OS === 'web') return false;
if (minor >= 50) {
return DeviceInfo.isIPhoneX_deprecated;
}

return (
Platform.OS === 'ios'
&& ( (D_HEIGHT === X_HEIGHT && D_WIDTH === X_WIDTH)
|| (D_HEIGHT === X_WIDTH && D_WIDTH === X_HEIGHT))
Platform.OS === 'ios' &&
((D_HEIGHT === X_HEIGHT && D_WIDTH === X_WIDTH) ||
(D_HEIGHT === X_WIDTH && D_WIDTH === X_HEIGHT)) ||
((D_HEIGHT === XSMAX_HEIGHT && D_WIDTH === XSMAX_WIDTH) ||
(D_HEIGHT === XSMAX_WIDTH && D_WIDTH === XSMAX_HEIGHT))
);
})();

var Theme = {
const isIPad = (() => {
if (Platform.OS !== 'ios' || isIPhoneX) return false;

// if portrait and width is smaller than iPad width
if (D_HEIGHT > D_WIDTH && D_WIDTH < PAD_WIDTH) {
return false;
}

// if landscape and height is smaller that iPad height
if (D_WIDTH > D_HEIGHT && D_HEIGHT < PAD_WIDTH) {
return false;
}

return true;
})();


const Theme = {

themes: {
default: ThemeDefault,
Expand All @@ -44,7 +62,7 @@ var Theme = {
Object.assign(this, theme);
},

isPad: isPad,
isPad: isIPad,

isIPhoneX: isIPhoneX,

Expand Down

0 comments on commit d7bb0b2

Please sign in to comment.