The moment it touches the screen edge, its direction flips and that speed is multiplied by a restitution factor, so the ball settles down little by little with every bounce.