function enableInteractivityOnButtonDown(ax_or_uiaxes)
%ENABLEINTERACTIVITYONBUTTONDOWN enables interactions on buttondown

% This function disables both default interactions and the axes toolbar and
% enables them again on the first buttondown. Subsequent buttondowns have
% no effect.

%   Copyright 2019 The MathWorks, Inc.

ax = findobjinternal(ax_or_uiaxes,'-isa','matlab.graphics.axis.AbstractAxes');
disableDefaultInteractivity(ax);

a = addlistener(ax,'Hit',@(o,e)noop());
a.Callback = @(o,e)enableInteractionsAndDelete(ax, a);
end

function enableInteractionsAndDelete(ax, a)
    enableDefaultInteractivity(ax)

    delete(a);
end
