Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26563

TiAPI: 2DMatrix translate() coordinate units do not match between platforms

    Details

      Description

      Summary:
      The 2DMatrix.translate() method's (x,y) values are handled inconsistently between platforms.

      On Android, the units are expected to be pixels (aka: "px").
      On iOS, the units are expected to be dips (aka: "dp").

      The translate() method should be changed to use the units assigned to the "tiapp.xml" file's "ti.ui.defaultunit" property. This way they would be handled consistently between platforms and the units which match the coordinates used by the window's views (makes the math easier to calculate).

      Steps to reproduce:
      For this animation test, a blue square is supposed to move from the top-left corner to the bottom-right corner.

      1. Set "tiapp.xml" property "ti.ui.defaultunit" to "dp".
      2. Build and run on iOS.
      3. Notice that the blue square correctly animated to bottom-right corner. (This is good.)
      4. Set "tiapp.xml" property "ti.ui.defaultunit" to "px".
      5. Build and run on iOS.
      6. Notice that the blue square moves off screen, past the bottom-right corner. (This is the bug.)
      7. Build and run on Android.
      8. Notice that the blue square correctly animated to bottom-right corner. (This is good.)
      9. Set "tiapp.xml" property "ti.ui.defaultunit" to "dp".
      10. Build and run on Android.
      11. Notice that the blue square does not reach the bottom-right corner. (This is the bug.)

      var SQUARE_SIZE = 80;
      var window = Ti.UI.createWindow({
      	backgroundColor: "white",
      	fullscreen: true,
      });
      var squareView = Ti.UI.createView({
      	backgroundColor: "blue",
      	left: 0,
      	top: 0,
      	width: SQUARE_SIZE,
      	height: SQUARE_SIZE,
      });
      window.add(squareView);
      window.addEventListener("postlayout", function() {
      	if (!squareView.wasAnimated) {
      		var windowSize = window.size;
      		var newX = windowSize.width - SQUARE_SIZE;
      		var newY = windowSize.height - SQUARE_SIZE;
      		var animation = Ti.UI.createAnimation({
      			transform: Ti.UI.create2DMatrix().translate(newX, newY),
      			duration: 2000,
      		});
      		squareView.wasAnimated = true;
      		squareView.animate(animation);
      	}
      });
      window.open();
      

      Note:
      This is not an issue with 2DMatrix.scale() since scaling is a "relative" operation. Versus translations works with "absolute" coordinates.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Vijay Singh
                Tester:
                Samir Mohammed
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-6708
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code