I have developed a native module which requires me to pass a view while opening the module controller. The module is basically a PDF Reader and I need to put a custom sharing button which I need to pass from Titanium code. This button view was visible and working perfectly fine with Classic Titanium apps and also working fine when I programmatically create the button. The only problem is now using Alloy, I created a separate control for the button and now it stopped working.
Below I have pasted snippet for demo code.
Here is my code which was working fine when used programmatic control:
App.js:
var shareBase = Ti.UI.createView({ width: 40, height: 40, top: 0, left: 0, backgroundColor: 'green' }); var shareview = Ti.UI.createView({ backgroundImage: 'shareview.png', width: 40, height: 40, }); shareBase.add(shareView); ... ... ... // Below is the code how I am passing the view for the module var PDF_READER = require('com.investis.docreader'); var document = PDF_READER.createPDFDocument(reportFile.nativePath.trim()); ... document.setCustomView(shareBase); // Share view is being passed document.setTitle(report.title); document.display();Controller in the module which accepts the view passed from Titanium code:
controller.m
- (void)setCustomView: (id)args { TiUIViewProxy *_argVw = args; if (!args) { NSLog(@"View Proxy nil", nil); } [_pdfViewController setCustomView: _argVw.view ]; // _argVw.view gets UIView from ViewProxy NSLog(@"View assigned here", nil); NSLog([_argVw description], nil); NSLog([_argVw.view description], nil); }
pdfViewController.m - The controller from where original PDF Reader is called, so I need to pass the view to this controller which loads the view into Toolbar
... _customButton = [[UIBarButtonItem alloc] initWithCustomView: _customView]; // _customView is the view which is passed from controller.m ... // Now display button items into toolbar toolbarItems = [NSArray arrayWithObjects:... _customButton, fixedSpace, ..., nil];The above code was working fine. But when I implemented the code as Alloy controller, the custom view is stopped being loaded from the controller.
App.js
var pdfshare = Alloy.createController("SocialShare", {}); ... document.setCustomView(pdfshare.getView()); // Passing custom view from the controller, other code in the file remain same ...Here is the code how
SocialShare
is created.
SocialShare.xml
<Alloy> <View id="container" class="container"> <View id="shareIt" onSingletap="shareIt" platform="ios"/> <View id="shareIt" onSingletap="shareItAndroid" platform="android" /> </View> </Alloy>
SocialShare.tss
".container":{ backgroundColor: 'yellow', borderWidth: 2, borderColor: 'black', right: 0, bottom: 0 }, ".container[formFactor=tablet]":{ height: 43, width: 43 }, ".container[formFactor=handheld]":{ height: 40, width: 40 }
SocialShare.js
var args = arguments[0] || {}; ... // Here nothing extra ordinary UI related tasks are performed. Only event handlers for shareItThe same code at Module side but still it stopped working. If I pass view generated programmatically then it works fine. Let me know if we need to treat Alloy views differently or not. I have searched a lot over Google and read through docs but unable to find any proper solution.
Details:- Titanium SDK: 3.2.3.GA Alloy: 1.3.0 iPhone Simulator: 7.1
Let me know if there is any solution around this or any patch.