Many iPhone users are facing issue in iOS 11 or even on iOS 11.3 and iOS 11.4 beta, that proximity sensor is turning on or active. If you cover it with your finger the display shuts off, this is in apps or the homes screen. The proximity sensor in iPhone is near the front camera to detect when you are listening to call by placing it near to phone and it will turn off the screen of iPhone so that random touches does not happens accidently on the call screen.
But the iPhone X and iPhone 7+ users are complaining that the sensor is turning on while not on a call and using any apps, and suddenly the screen goes out black. Which is really an annoying bug in the iOS? Restarting the iPhone will help to solve the proximity sensor issue temporarily but the issue occurs again after sometime when you make next call.
This does not only affect the user experience while using the iPhone but also may impact on battery life. There are no updates from the Apple on this issue so far but many report have been submitted to Apple this proximity sensor bug in iPhone.
You can try to fix the issue by Hard resetting your iPhone, which seems to work for many iPhone users for now. If hard reset never fix this issue you should get iPhone checked at nearest authorized dealer as this may also happen due to hardware fault, which likely to occur after screen replacement, iPhone dropping on hard surface etc.