Add check for current UI being unset in ViewScopedContext (#14900)

Change-Id: I2be7e557843eaa7c7fc53df15759752b71975a95