It looks like the part might still be good.
If you detach the small board, lay the board flat, place the detached optical section back in place, and heat in a toaster oven.. you could get the soldier to re-flow, and probably get the part to attach just fine.
Do some research into reflow, and temperature and duration... as too little = no reflow... and too much.. can melt plastics and or kill components.
I do not think the optical sensor that fell off is broke in half. I believe its actually two individual sensor chips, based on the 4 solder ball points
on each chip.
New non-lead based solder has a lot of problems with good smooth flow... and as such, there is probably a 50% failure rate on all modern electronic circuit boards, as a result. These failures can happen immediately, a few months, or even years down the road. Temperature changes, vibrations, can cause the already weak connections to break free. Also, there tends to be small micro-spikes in the process... and these spikes can break off, and cause electronic shorts.
Also, you may first want to clean the parts with rubbing alcohol, then apply some decent quality flux. The flux greatly aids in flow and bonding.