Here is what's happening:

I have read about this happening with the Moto G4 and supposedly you can correct it by turning the battery optimizaton ON for all apps or turning it OFF for all apps or turning the adaptive brightness ON or turning it OFF. But in fact none of these changes makes any difference. I still have that annoying screen flicker. And this is probably related to the problem I sometimes have unlocking the screen by swiping up.

Any ideas?