Reversible tuning of optical metasurfaces