-
Notifications
You must be signed in to change notification settings - Fork 21
Creating a Widget Section
This article details how to create a widget section which you can either register RAWidgets or return your own views.
An example could be a section with simple media player controls.
First, read how to create a widget.
- Create your header
#import <ReachApp/RAWidgetSection.h>
@interface MyRASection : RAWidgetSection
@end
Easy, right?
- Implement the section
@implementation MyRASection
-(BOOL) enabled { return isMyTweakEnabled(); }
-(NSString*) displayName
{
return @"My Section";
}
-(NSString*) identifier
{
// Must be unique!
return @"com.sample.mysection";
}
Please note: the preferredIconSize, iconsThatFitPerLine, and spacing are for if you plan on implementing an icon list similar to the default Recent, AllApps, or Favorite icon sections.
If you have a static view that doesn't change you can cache the view (using a static variable) and return that to speed up loading time.
-(UIView*) viewForFrame:(CGRect)frame preferredIconSize:(CGSize)size iconsThatFitPerLine:(NSInteger)iconsPerLine spacing:(CGFloat)spacing
{
... this is where you can return some list, or some custom view, or something ...
}
@end
- Some quick notes
- The
displayNameandidentifiermethods must be overridden or they will throw exceptions at runtime. - Overriding
addWidget:allows you to do something else with the passed inRAWidget*if you want to. - in the
viewForFrame:preferredIconSize:iconsThatFitPerLine:spacing:method, if you returnnilthen the section is hidden. Sometimes doing that instead of some complicated checks in theenabledmethod can speed up loading time (See theRAFavoriteAppsWidget.xmfile for an example of this). - The
heightof the frame is arbitrary and irrelevant - you can resize the height to anything you want.
- Registering your section
static id MyRASection$instance = nil;
%ctor
{
dlopen("/Library/MobileSubstrate/DynamicLibraries/ReachApp.dylib", RTLD_GLOBAL | RTLD_NOW);
MyRASection$instance = [[%c(MyRASection) alloc] init];
[%c(RAWidgetSectionManager) sharedInstance] registerSection:MyRASection$instance];
}
Other notes
-
You can override the sort order (where in the Reachability view it shows - above or below other sections) of the sections by overriding the
-(NSInteger) sortOrder;method. By default it is10and the default app chooser sections range from1-3. -
You can override
-(BOOL)showTitleto determine whether or not your section should show the title or not... It's best to leave the title on unless you have a good reason for having it off.