Increasing the coherence time of Bose-Einstein-condensate interferometers with optical control of dynamics