Project: titanium
Issue TIMOB-20055: iOS: Refactor previewContext to be more memory-efficient
The current {{Ti.UI.iOS.PreviewContent}} implementation works. But to make it even more efficient related to memory management, I refactored a few parts: - Remove manual properties of {{TiUIiOSPreviewContext}} inside the {{TiPreviewingDelegate}} and access them through the {{previewContext}} property (since the delegate is not public and it keeps the object dependencies clean) - Release some properties that have not been released before - Add missing code docs in the {{TiPreviewingDelegate}} header file - Change counter index from {{int}} to {{NSUInteger}} and remove unused {{actionGroupIndex}} property that have been used during testing - Enable ARC in all related files (!) Demo code (should work exactly like before): {code:javascript} var actions = []; var win = Ti.UI.createWindow({ backgroundColor: "white" }); // The view to be previewed while popping. var previewView = Ti.UI.createView({ backgroundColor: "blue" }); // The window to be opened after popping the preview. var detailWindow = Ti.UI.createWindow({ backgroundColor: "yellow" }); detailWindow.add(Ti.UI.createLabel({ text: "You made it!" })); // The actions to be added to the preview context. var action = Ti.UI.iOS.createPreviewAction({ title: "Preview Action", style: Ti.UI.iOS.PREVIEW_ACTION_STYLE_DEFAULT }); action.addEventListener("click", function(e) { alert("Title: " + e.title + " / Style: " + e.style+" / Index: " + e.index); }); var subAction = Ti.UI.iOS.createPreviewAction({ title: "Preview Subaction" }) subAction.addEventListener("click", function(e) { alert("Title: " + e.title + " / Style: " + e.style+" / Subindex: " + e.index); }); var actionGroup = Ti.UI.iOS.createPreviewActionGroup({ title: "More actions...", style: Ti.UI.iOS.PREVIEW_ACTION_STYLE_DESTRUCTIVE, actions: [subAction] }); actions.push(action); actions.push(actionGroup); // Create the preview context var context = Ti.UI.iOS.createPreviewContext({ preview: previewView, actions: actions, // Can have both Ti.UI.iOS.PreviewAction + Ti.UI.iOS.PreviewActionGroup contentHeight: 300 // When unspecified, we use the available height }); // Fired after popping the preview context.addEventListener("pop", function(e) { detailWindow.open(); }); // Assign the preview context var button = Ti.UI.createButton({ previewContext: context, // Will be ignored on unsupported devices title : "Open Window!", backgroundColor: "#A6171C", width: 200, height: 50, tintColor: "#fff" }); win.add(button); win.open(); {code}
Story points: 3