{"action":"created","issue":{"url":"https://api.github.com/repos/NativeScript/android-runtime/issues/604","repository_url":"https://api.github.com/repos/NativeScript/android-runtime","labels_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/604/labels{/name}","comments_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/604/comments","events_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/604/events","html_url":"https://github.com/NativeScript/android-runtime/issues/604","id":186221861,"number":604,"title":"Help needed with Android ViewPager PageTransformer","user":{"login":"NickIliev","id":18008302,"avatar_url":"https://avatars.githubusercontent.com/u/18008302?v=3","gravatar_id":"","url":"https://api.github.com/users/NickIliev","html_url":"https://github.com/NickIliev","followers_url":"https://api.github.com/users/NickIliev/followers","following_url":"https://api.github.com/users/NickIliev/following{/other_user}","gists_url":"https://api.github.com/users/NickIliev/gists{/gist_id}","starred_url":"https://api.github.com/users/NickIliev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickIliev/subscriptions","organizations_url":"https://api.github.com/users/NickIliev/orgs","repos_url":"https://api.github.com/users/NickIliev/repos","events_url":"https://api.github.com/users/NickIliev/events{/privacy}","received_events_url":"https://api.github.com/users/NickIliev/received_events","type":"User","site_admin":false},"labels":[{"id":216228126,"url":"https://api.github.com/repos/NativeScript/android-runtime/labels/Android","name":"Android","color":"ededed","default":false},{"id":213419193,"url":"https://api.github.com/repos/NativeScript/android-runtime/labels/T:Question","name":"T:Question","color":"eeeeee","default":false}],"state":"open","locked":false,"assignee":{"login":"Pip3r4o","id":10464986,"avatar_url":"https://avatars.githubusercontent.com/u/10464986?v=3","gravatar_id":"","url":"https://api.github.com/users/Pip3r4o","html_url":"https://github.com/Pip3r4o","followers_url":"https://api.github.com/users/Pip3r4o/followers","following_url":"https://api.github.com/users/Pip3r4o/following{/other_user}","gists_url":"https://api.github.com/users/Pip3r4o/gists{/gist_id}","starred_url":"https://api.github.com/users/Pip3r4o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pip3r4o/subscriptions","organizations_url":"https://api.github.com/users/Pip3r4o/orgs","repos_url":"https://api.github.com/users/Pip3r4o/repos","events_url":"https://api.github.com/users/Pip3r4o/events{/privacy}","received_events_url":"https://api.github.com/users/Pip3r4o/received_events","type":"User","site_admin":false},"assignees":[{"login":"Pip3r4o","id":10464986,"avatar_url":"https://avatars.githubusercontent.com/u/10464986?v=3","gravatar_id":"","url":"https://api.github.com/users/Pip3r4o","html_url":"https://github.com/Pip3r4o","followers_url":"https://api.github.com/users/Pip3r4o/followers","following_url":"https://api.github.com/users/Pip3r4o/following{/other_user}","gists_url":"https://api.github.com/users/Pip3r4o/gists{/gist_id}","starred_url":"https://api.github.com/users/Pip3r4o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pip3r4o/subscriptions","organizations_url":"https://api.github.com/users/Pip3r4o/orgs","repos_url":"https://api.github.com/users/Pip3r4o/repos","events_url":"https://api.github.com/users/Pip3r4o/events{/privacy}","received_events_url":"https://api.github.com/users/Pip3r4o/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2016-10-31T07:35:42Z","updated_at":"2016-10-31T09:20:57Z","closed_at":null,"body":"_From @alexrainman on October 28, 2016 13:35_\n\nI have this custom ViewPager that overrides touch gestures to support vertical swipe:\n\n```\n    export class VerticalViewPager extends android.support.v4.view.ViewPager\n    {\n        constructor(context: android.content.Context, attrs?: android.util.IAttributeSet){\n            super(context, attrs);\n            //this.setPageTransformer(false, new DefaultTransformer());\n            return global.__native(this);\n        }\n\n        private swapTouchEvent(ev: android.view.MotionEvent)\n        {\n            var width = this.getWidth();\n            var height = this.getHeight();\n\n            var swappedX = (ev.getY() / height) * width;\n            var swappedY = (ev.getX() / width) * height;\n\n            ev.setLocation(swappedX, swappedY);\n\n            return ev;\n        }\n\n        public onInterceptTouchEvent(ev: android.view.MotionEvent)\n        {\n            var intercept = super.onInterceptTouchEvent(this.swapTouchEvent(ev));\n            //If not intercept, touch event should not be swapped.\n            this.swapTouchEvent(ev);\n            return intercept;\n        }\n\n        public onTouchEvent(ev: android.view.MotionEvent)\n        {\n            return super.onTouchEvent(this.swapTouchEvent(ev));\n        }\n    }\n```\n\nThis works fine but i have to apply a page transformer to enable vertical scrolling, that's the part that doesn't works.\n\nNormally i implement the PageTransformer like this (and this works in well in Java):\n\n```\n   export class DefaultTransformer implements android.support.v4.view.ViewPager.IPageTransformer\n    {\n        public transformPage(page: android.view.View, position: number): void\n        {\n            page.setTranslationX(page.getWidth() * -position);\n            var yPosition = position * page.getHeight();\n            page.setTranslationY(yPosition);\n        }\n    }\n```\n\nBut i do it like that i get this exception:\n\n```\nError: Cannot convert object to Landroid/support/v4/view/ViewPager$PageTransformer; at index 1\n```\n\nAs i had kind of the same issue in Xamarin, then i'm doing this:\n\n```\n    export class DefaultTransformer extends java.lang.Object implements android.support.v4.view.ViewPager.IPageTransformer\n    {\n        constructor()\n        {\n            super();\n            return global.__native(this);\n        }\n        public transformPage(page: android.view.View, position: number): void\n        {\n            page.setTranslationX(page.getWidth() * -position);\n            var yPosition = position * page.getHeight();\n            page.setTranslationY(yPosition);\n        }\n    }\n```\n\nBut then i get this exception:\n\n```\nError: No java object found on which to call \"setPageTransformer\" method. It is possible your Javascript object is not linked with the corresponding Java class. Try passing context(this) to the constructor function.\n```\n\nI am passing context to the constructor. Any ideas?\n\n\n_Copied from original issue: NativeScript/NativeScript#2981_"},"comment":{"url":"https://api.github.com/repos/NativeScript/android-runtime/issues/comments/257247066","html_url":"https://github.com/NativeScript/android-runtime/issues/604#issuecomment-257247066","issue_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/604","id":257247066,"user":{"login":"Pip3r4o","id":10464986,"avatar_url":"https://avatars.githubusercontent.com/u/10464986?v=3","gravatar_id":"","url":"https://api.github.com/users/Pip3r4o","html_url":"https://github.com/Pip3r4o","followers_url":"https://api.github.com/users/Pip3r4o/followers","following_url":"https://api.github.com/users/Pip3r4o/following{/other_user}","gists_url":"https://api.github.com/users/Pip3r4o/gists{/gist_id}","starred_url":"https://api.github.com/users/Pip3r4o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pip3r4o/subscriptions","organizations_url":"https://api.github.com/users/Pip3r4o/orgs","repos_url":"https://api.github.com/users/Pip3r4o/repos","events_url":"https://api.github.com/users/Pip3r4o/events{/privacy}","received_events_url":"https://api.github.com/users/Pip3r4o/received_events","type":"User","site_admin":false},"created_at":"2016-10-31T09:20:57Z","updated_at":"2016-10-31T09:20:57Z","body":"Hey @alexrainman!\r\n\r\nFirst off, what you did with DefaultTransformeer is not how interface implementations work in NativeScript. You can either extend java.lang.Object and decorate the class with @Interfaces([]), or write an inline implementation of the interface. Second off, the interface is just `ViewPager.PageTransformer` as opposed to `ViewPager.*I*PageTransformer`\r\n\r\nLast, in your ViewPager's implementation constructor you return `global.__native(this)` this is necessary in typescript to return a reference to the Java Object, otherwise TS would return just a JavaScript wrapper. To be able to work on that Java instance before you've finished constructing the object, you would need to again call the method on \r\n```typescript\r\nglobal.__native(this).setPageTransformer(false, new android.support.v4.view.ViewPager.PageTransformer({\r\n      transformPage(page: android.view.View, position: number): void {\r\n        page.setTranslationX(page.getWidth() * -position);\r\n        var yPosition = position * page.getHeight();\r\n        page.setTranslationY(yPosition);\r\n      }\r\n    })\r\n```\r\n\r\nor alternatively \r\n\r\n```typescript\r\n@Interfaces([android.support.v4.view.ViewPager.PageTransformer])\r\nexport class DefaultTransformer extends java.lang.Object {\r\n  transformPage(page: android.view.View, position: number): void { ... }\r\n}\r\n```"}}
{"actor":{"display_login":"Pip3r4o"}}