Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add stopAnimation() to View #13743

Merged
merged 1 commit into from
Mar 12, 2023
Merged

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Feb 10, 2023

Old PR: #10130
Moving it to a new PR so the checks will be green again.


Android has no possibility to cancel/stop animations like moving an object from left to right before the duration is over. This PR adds a stopAnimation() method to Ti.UI.View

const win = Ti.UI.createWindow();

const lbl = Ti.UI.createLabel({
	text: "-",
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE
});

const view = Ti.UI.createView({
	backgroundColor: 'red',
	height: 100,
	width: 100,
	top: 0,
	left: 0
});

const btn1 = Ti.UI.createButton({
	title: 'Animate',
	width: 100,
	height: 40,
	bottom: 20,
	left: 10
});
btn1.addEventListener('click', function() {
	view.left = 0;
	view.animate(ani);
});

const btn2 = Ti.UI.createButton({
	title: 'Cancel',
	width: 100,
	height: 40,
	bottom: 20,
	right: 10
});
btn2.addEventListener('click', function() {
	view.stopAnimation();
	view.left = 0;
});

const ani = Ti.UI.createAnimation({
	left: 100,
	duration: 3000
})

ani.addEventListener("start", function() {
	lbl.text = "start";
});

ani.addEventListener("complete", function() {
	lbl.text = "complete";
})

ani.addEventListener("cancel", function() {
	lbl.text = "cancel";
})

win.add([view, btn1, btn2, lbl]);
win.open();

@mitulbhalia
Copy link

Tested demo code and other apps. All are working fine.

@hansemannn hansemannn merged commit 0d4829b into master Mar 12, 2023
@m1ga m1ga deleted the 230210_anistop branch May 3, 2023 21:35
narbs pushed a commit to narbs/titanium_mobile that referenced this pull request Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants