I had the same issue, brand new out of the box iPhone 7 Plus, and the camera wasn't focusing at all.
The portrait mode was ok, but not other modes... Noticed that when I was trying to get my credit cards
added to Apple Pay (Wallet)... It looks like the camera stabilization mechanism is causing the issue.
Tried resetting, hard reset, restoring factory defaults, bla bla bla... nothing worked!
My solution: believe or not, I had to hit my iPhone (the camera part) gently on the palm of my hand a
few times and whatever was stuck got released and my camera started working, focus was back...
I'm not saying you should do that with yours, consult an Apple employee for advice, this only worked
for my iPhone so far. I'm going to an Apple store and report that, don't want to have the same problem
after the warrant expires. Apple should look at this issue with more details!
PS.: the camera area was overheating when the focus issue was apparent and went away after the
my "horrible" solution worked...