Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Creating a Widget Section

Elijah Frederickson edited this page Jan 31, 2015 · 5 revisions

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.


  1. Create your header
#import <ReachApp/RAWidgetSection.h>

@interface MyRASection : RAWidgetSection
@end

Easy, right?

  1. 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
  1. Some quick notes
  • The displayName and identifier methods must be overridden or they will throw exceptions at runtime.
  • Overriding addWidget: allows you to do something else with the passed in RAWidget* if you want to.
  • in the viewForFrame:preferredIconSize:iconsThatFitPerLine:spacing: method, if you return nil then the section is hidden. Sometimes doing that instead of some complicated checks in the enabled method can speed up loading time (See the RAFavoriteAppsWidget.xm file for an example of this).
  • The height of the frame is arbitrary and irrelevant - you can resize the height to anything you want.
  1. 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

  1. 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 is 10 and the default app chooser sections range from 1-3.

  2. You can override -(BOOL)showTitle to 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.

Clone this wiki locally