Perhaps the proximity sensor is not working properly. (just to make a test, try to pull out the case).
Sometimes a forced restart can help in such a situation too:
Press and quickly release the Volume Up button. Press and quickly release the Volume Down button. Then press and hold the Side button until you see the Apple logo. When it appears, relase the Side button, wait for your iPhone to restart, then test it.
If you get no improvements, since your XR is still covered by warranty, have it inspected at an Apple Store or Authorized Service Provider: Apple–LocationSelector
Regards
Giulio