-
-
Save grantges/8bd9ff0403bd5887d5bf to your computer and use it in GitHub Desktop.
Hyperloop Memory Leak issues with 3rd Party Modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implementation of the GLCalendarView 3rd Party Library for iOS | |
* using Appcelerator Hyperloop. | |
* | |
* Credits go to Glow-Inc (https://github.com/Glow-Inc/GLCalendarView) | |
* for their great open source calendar! | |
*/ | |
(function(container){ | |
// Require in core native classes | |
var CGRectMake = require('CoreGraphics').CGRectMake, | |
UIView = require('UIKit/UIView'), | |
UIScreen = require('UIKit/UIScreen'), | |
UIColor = require('UIKit/UIColor'), | |
NSDate = require('Foundation/NSDate'), | |
NSObject = require('Foundation/NSObject'); | |
// Require in 3rd Party Native Classes | |
var GLCalendarView = require('GLCalendarView/GLCalendarView'), | |
GLCalendarDateRange = require('GLCalendarView/GLCalendarDateRange'), | |
GLDateUtils = require('GLCalendarView/GLDateUtils'); | |
var calendar, delegate, currentSelectedRange; | |
/** | |
* Create a native class to act as the delegate of the GLCalendarView. | |
* A delegate is similar to an Alloy javascript controller file for the XML | |
* view. It is responsible for interacting with the UI elements. | |
* | |
* GLCalendarView Obj- C Delegate Protocol Reference | |
* ================================================= | |
* @protocol GLCalendarViewDelegate <NSObject> | |
* - (BOOL)calenderView:(GLCalendarView *)calendarView canAddRangeWithBeginDate:(NSDate *)beginDate; | |
* - (GLCalendarDateRange *)calenderView:(GLCalendarView *)calendarView rangeToAddWithBeginDate:(NSDate *)beginDate; | |
* - (void)calenderView:(GLCalendarView *)calendarView beginToEditRange:(GLCalendarDateRange *)range; | |
* - (void)calenderView:(GLCalendarView *)calendarView finishEditRange:(GLCalendarDateRange *)range continueEditing:(BOOL)continueEditing; | |
* - (BOOL)calenderView:(GLCalendarView *)calendarView canUpdateRange:(GLCalendarDateRange *)range toBeginDate:(NSDate *)beginDate endDate:(NSDate *)endDate; | |
* - (void)calenderView:(GLCalendarView *)calendarView didUpdateRange:(GLCalendarDateRange *)range toBeginDate:(NSDate *)beginDate endDate:(NSDate *)endDate; | |
* @optional | |
* - (NSArray *)weekDayTitlesForCalendarView:(GLCalendarView *)calendarView; | |
* @end | |
*/ | |
var CalendarDelegate = Hyperloop.defineClass('CalendarDelegate', 'NSObject'); | |
/** | |
* Implement the required delegate methods that are defined by the | |
* GLCalendarView | |
*/ | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:canAddRangeWithBeginDate:', | |
instance: true, | |
encoding: 'c@:@@', | |
callback: function(view, beginDate){ | |
return true; | |
} | |
}); | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:rangeToAddWithBeginDate:', | |
instance: true, | |
encoding: '@@:@@', | |
callback: function(calendarView, beginDate){ | |
var start = NSDate.cast(beginDate); | |
Ti.API.info(start); | |
var endDate = GLDateUtils.dateByAddingDaysToDate(2, start); | |
var range = GLCalendarDateRange.rangeWithBeginDateEndDate(start, endDate); | |
range.backgroundColor = UIColor.redColor(); | |
range.editable = true; | |
return range; | |
} | |
}); | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:beginToEditRange:', | |
instance: true, | |
encoding: 'v@:@@', | |
callback: function(view, range){ | |
Ti.API.info('calenderView:beginToEditRange:'); | |
Ti.API.info(GLCalendarDateRange.cast(range)); | |
currentSelectedRange = GLCalendarDateRange.cast(range); | |
return; | |
} | |
}); | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:finishEditRange:continueEditing:', | |
instance: true, | |
encoding: 'v@:@@@', | |
callback: function(view, range, continueEditing){ | |
currentSelectedRange = null; | |
return; | |
} | |
}); | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:canUpdateRange:toBeginDate:endDate:', | |
instance: true, | |
encoding: 'c@:@@@@', | |
callback: function(view, range, beginDate, endDate){ | |
return true; | |
} | |
}); | |
CalendarDelegate.addMethod({ | |
selector: 'calenderView:didUpdateRange:toBeginDate:endDate:', | |
instance: true, | |
encoding: 'v@:@@@@', | |
callback: function(view, range, beginDate, endDate){ | |
Ti.API.info('Did Update Range' + GLCalendarDateRange.cast(range)); | |
return; | |
} | |
}); | |
// Get the screensize | |
var bounds = UIScreen.mainScreen().bounds | |
var frame = CGRectMake(0, 0, bounds.size.width, bounds.size.height); | |
var today = NSDate.date(); | |
calendar = new GLCalendarView(); | |
delegate = new CalendarDelegate(); | |
// Setup the GLCalendarView | |
calendar.frame = frame; | |
calendar.delegate = delegate; | |
calendar.firstDate = GLDateUtils.dateByAddingDaysToDate(-182, today); | |
calendar.lastDate = GLDateUtils.dateByAddingDaysToDate(182, today); | |
// Add GLCalendarView to the Titanium View container | |
container.add(calendar); | |
calendar.reload(); | |
/** | |
* Add Click Event Listener for the Right Nav Button | |
* This event listener scrolls the calendar to the current day of the calendar. | |
*/ | |
$.deleteButton.addEventListener('click', removeCurrentRange); | |
/** | |
* Removes the currently selected range from the CalendarView | |
*/ | |
function removeCurrentRange(){ | |
if(currentSelectedRange){ | |
calendar.removeRange(currentSelectedRange); | |
currentSelectedRange = null; | |
} | |
} | |
/** | |
* Scroll to Today's date once the view is loaded. | |
*/ | |
container.addEventListener('postlayout', function(e){ | |
calendar.scrollToDateAnimated(today, false); | |
}); | |
})($.calendar_container); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window id="win" title="GLCalendar"> | |
<View> | |
<Label>3rd Party 3D Globe Library</Label> | |
<View class="vbox" id="calendar_container"></View> | |
</View> | |
</Window> | |
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<!-- | |
The module-attribute will result in require('xp.ui').createNavigationWindow() | |
See app/lib/xp.ui.js for how we use this to emulate the iOS-only NavigationWindow for Android | |
--> | |
<NavigationWindow id="navWin" module="xp.ui"> | |
<Window title="Samples"> | |
<ListView onItemclick="onListViewItemclick"> | |
<ListSection> | |
<ListItem itemId="autolayout" platform="ios" title="Auto Layout"/> | |
<ListItem itemId="touchid" platform="ios" title="Apple Touch ID"/> | |
<ListItem itemId="animateview" title="View Animation"/> | |
<ListItem itemId="label" title="Styled Labels"/> | |
<ListItem itemId="drawrect" title="Custom Drawing"/> | |
<ListItem itemId="touches" title="Touches"/> | |
<ListItem itemId="calendar" platform="ios" title="GLCalendar (3rd Party Integration)"/> | |
<ListItem itemId="charting" platform="ios" title="Charting (3rd party integration)"/> | |
<ListItem itemId="alert" title="Alert"/> | |
<ListItem itemId="xib" platform="ios" title="Interface Builder UI"/> | |
<ListItem itemId="donutchart" title="Donut Chart"/> | |
<ListItem itemId="shapes" platform="ios" title="Shapes & Animation"/> | |
<ListItem itemId="custom" platform="ios" title="Custom Class"/> | |
<ListItem itemId="tinder" platform="ios" title="Tinder UI"/> | |
<ListItem itemId="gravity" platform="ios" title="Gravity"/> | |
<ListItem itemId="tableview" platform="ios" title="Table View"/> | |
</ListSection> | |
</ListView> | |
</Window> | |
</NavigationWindow> | |
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
platform :ios, '7.0' | |
target 'Hyperloop_Sample' do | |
pod 'JBChartView' | |
pod 'GLCalendarView', '~> 1.2' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment