Long time ago I’d use a third party app for that, but I don’t really trust them enough for that now. The closest solution I found was to use the work profile with Shelter, would that be the way to go?
In my case the app is Facebook Messenger & phone is Pixel 6.
I think Samsung devices also had a built in way to do this
Pretty sure it’s being delayed until October, they’re releasing the Pixel 8 alongside it