This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f57bd04
commit a44b1f0
Showing
5 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { InfoPlist } from './IosConfig.types'; | ||
import { ExpoConfig } from '../Config.types'; | ||
|
||
export function getSupportsTablet(config: ExpoConfig) { | ||
if (config.ios?.supportsTablet) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function getIsTabletOnly(config: ExpoConfig) { | ||
if (config.ios?.isTabletOnly) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function getDeviceFamilies(config: ExpoConfig) { | ||
let supportsTablet = getSupportsTablet(config); | ||
let isTabletOnly = getIsTabletOnly(config); | ||
|
||
// 1 is iPhone, 2 is iPad | ||
if (isTabletOnly) { | ||
return [2]; | ||
} else if (supportsTablet) { | ||
return [1, 2]; | ||
} else { | ||
return [1]; | ||
} | ||
} | ||
|
||
export function setDeviceFamily(config: ExpoConfig, infoPlist: InfoPlist) { | ||
return { | ||
...infoPlist, | ||
UIDeviceFamily: getDeviceFamilies(config), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
getDeviceFamilies, | ||
getIsTabletOnly, | ||
getSupportsTablet, | ||
setDeviceFamily, | ||
} from '../DeviceFamily'; | ||
|
||
const TABLET_AND_PHONE_SUPPORTED = [1, 2]; | ||
const ONLY_PHONE_SUPPORTED = [1]; | ||
const ONLY_TABLET_SUPPORTED = [2]; | ||
|
||
describe('device family', () => { | ||
it(`returns false ios.isTabletOnly is not provided`, () => { | ||
expect(getIsTabletOnly({ ios: {} })).toBe(false); | ||
}); | ||
|
||
it(`returns true ios.isTabletOnly is provided`, () => { | ||
expect(getIsTabletOnly({ ios: { isTabletOnly: true } })).toBe(true); | ||
}); | ||
|
||
it(`returns false ios.supportsTablet is provided`, () => { | ||
expect(getSupportsTablet({ ios: {} })).toBe(false); | ||
}); | ||
|
||
it(`returns true ios.supportsTablet is provided`, () => { | ||
expect(getSupportsTablet({ ios: { supportsTablet: true } })).toBe(true); | ||
}); | ||
|
||
it(`supports tablet and mobile if supportsTablet is true`, () => { | ||
expect(getDeviceFamilies({ ios: { supportsTablet: true } })).toEqual( | ||
TABLET_AND_PHONE_SUPPORTED | ||
); | ||
}); | ||
|
||
it(`supports only mobile if supportsTablet is blank/false and isTabletOnly is blank/false`, () => { | ||
expect(getDeviceFamilies({ ios: {} })).toEqual(ONLY_PHONE_SUPPORTED); | ||
expect(getDeviceFamilies({ ios: { supportsTablet: false, isTabletOnly: false } })).toEqual( | ||
ONLY_PHONE_SUPPORTED | ||
); | ||
}); | ||
|
||
it(`supports only tablet if isTabletOnly is true`, () => { | ||
expect(getDeviceFamilies({ ios: { isTabletOnly: true } })).toEqual(ONLY_TABLET_SUPPORTED); | ||
}); | ||
|
||
it(`sets to phone only if no value is provided`, () => { | ||
expect(setDeviceFamily({}, {})).toMatchObject({ UIDeviceFamily: ONLY_PHONE_SUPPORTED }); | ||
}); | ||
|
||
it(`sets to given config when provided`, () => { | ||
expect(setDeviceFamily({ ios: { supportsTablet: true } }, {})).toMatchObject({ | ||
UIDeviceFamily: TABLET_AND_PHONE_SUPPORTED, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters