Skip to main content

Timer Considerations

When using transitions, it is very important to consider when to begin the timer.

OnAppear or OnSetup?

In the previous example, the code to begin the timer is in the sceneTwo.onAppear() event handler, which happens when the second screen has fully slid into view and stopped moving. With practice, you can probably achieve a response time of less than 300 or 400 milliseconds, because you know where the "CLICK ME!" button will appear.

On the other hand, consider if the code to begin the timer is placed in the sceneTwo.onSetup() event handler:

sceneTwo.onSetup(() => {
backButton.hidden = true;
clickMeButton.hidden = true;
console.log("sceneTwo onSetup event");
clickMeButton.hidden = false;
clickMeButton.isUserInteractionEnabled = true;
Timer.startNew("rt");
});

Compare your performance here versus the previous example.

With this code, it will be impossible to achieve a response time of less than 500 milliseconds. The timer begins before the second scene has finished its transition, which has duration 500 milliseconds. Even if the user clicks the "CLICK ME!" button as it is sliding into view, it will not accept interactions until the transition is complete.

tip

In most situations, to time a user behavior that starts with a new scene, the code to start the timer should be in the OnAppear event handler.

Loading...