[TIMOB-25804] iOS: Bar Image is not showing properly in iPhone X
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | None |
| Status | Resolved |
| Resolution | Not Our Bug |
| Resolution Date | 2019-04-12T18:43:11.000+0000 |
| Affected Version/s | Release 7.0.2 |
| Fix Version/s | n/a |
| Components | iOS |
| Labels | barimage, engTriage, ios, ios11, safearea |
| Reporter | Motiur Rahman |
| Assignee | Vijay Singh |
| Created | 2018-02-24T09:04:39.000+0000 |
| Updated | 2019-04-12T18:43:11.000+0000 |
Description
Issue: For iPhone X, bar image is not showing properly as like iPhone 8 and other. Always crop top portion.
Steps To Reproduce:
1. Create a new Alloy App.
2. Use the following test code and image then run it on iOS X and iOS 8 for checking the difference.
<Alloy>
<TabGroup id="tabGroup">
<Tab id="tab" title="My Tab" icon="myicon.png">
<Window barImage = "/images/relevent-dark-header.png">
</Window>
</Tab>
</TabGroup>
</Alloy>
Thanks!
Attachments
| File | Date | Size |
|---|---|---|
| example-fixed.png | 2018-02-24T22:43:18.000+0000 | 175558 |
| iPhone8.png | 2018-02-24T08:57:38.000+0000 | 1890051 |
| iPhoneX.png | 2018-02-24T08:57:38.000+0000 | 1429668 |
| relevent-dark-header.png | 2018-02-24T08:57:29.000+0000 | 14218 |
| TestNavBar.zip | 2018-02-26T08:17:26.000+0000 | 81164 |
There is a general issue here: Bar images have always been hard to manage when it comes to devices of different size and scale. In this case, the iPhone X requires a different bar-image height than all other devices. Reading some native discussions about this topic (like [here](https://www.devno.com/1242-ios-11-iphone-x-navigationbar-background-image-too-small/)), the use case usually is a gradient or patterned view that is simply stretched. This is not possible in this case and I don't see an SDK change that would solve this design issue (let us know if you have one). So there are two short- and long-term options I could think of: - Use a larger image for the iPhone X that includes the safe area height (short term) - Replace bar-images with "real" navigation bar titles (long term) *EDIT*: Here is a solution:
Check if the current device is an iPhone X
Use a different image for that exact device
Looks like this: !example-fixed.png|thumbnail! And again: This is caused by the fact that the bar image is a non-stretchable image that cannot be reused on all possible devices. For a more modern approach, I would recommend to either use a custom navigation bar with a fixed spacing to the safe-area or move away from bar images and display the actual title, like larger apps do these days as well.var win = Ti.UI.createWindow({ backgroundColor: '#fff', barImage: getBarImage() }); var nav = Ti.UI.iOS.createNavigationWindow({ window: win }); nav.open(); function getBarImage() { if (isiPhoneX()) { return 'relevent-dark-header-iphonex.png' } return 'relevent-dark-header.png'; } function isiPhoneX() { if (Ti.Platform.displayCaps.logicalDensityFactor !== 3) { return false } return (Ti.Platform.displayCaps.platformWidth === 375 && Ti.Platform.displayCaps.platformHeight === 812) || (Ti.Platform.displayCaps.platformWidth === 375 && Ti.Platform.displayCaps.platformHeight === 812); }If we see in native app (Attached TestNavBar.zip) also, similar problem is there. If you see [here](https://stackoverflow.com/questions/46664822/how-to-set-navigation-bar-background-image-for-all-devices-including-iphone-x), it is suggested to use different image for iPhone X. Apart from what Hans has suggested, following approach can also be used if it suits the requirement - 1. If the barImage is single coloured image (only the image near title view is different)
2. If the barImage is patterned (only the image near title view is different)var win = Ti.UI.createWindow({ backgroundColor: '#fff', barColor: 'black', titleImage: 'relevent-dark-header.png', }); var nav = Ti.UI.iOS.createNavigationWindow({ window: win }); nav.open();var win = Ti.UI.createWindow({ backgroundColor: '#fff', barImage: 'Use the patterned image', titleImage: 'relevent-dark-header.png', }); var nav = Ti.UI.iOS.createNavigationWindow({ window: win }); nav.open();