adding the logic to prevent the gallery swiping beyond the maximum slides or before initial slide