openframeworks / openframeworks/openFrameworks

iOS - discussion on multiple view controllers

Open
#5,237 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

iOS prelim-analysis
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Opened per request from @arturoc.

In Android, we have recently added the ability to have multiple activities instantiated at the same time (instead of just crashing), and they all show the same ofApp (i.e, if you want to show different content in each activity, develop the ability yourself).

Link: https://github.com/openframeworks/openFrameworks/pull/5219

I added the same ability in iOS, but realized that I don’t actually need to change anything inside OF to support this. Since iOS supports nesting of view controllers, all I needed was to add and use this class:

#import "GLViewController.h"
#include "ofxiOS.h"
#include "ofAppMap.h"

ofxiOSViewController* m_ofViewController = NULL;
int m_refCount = 0;

@implementation GLViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    if (m_ofViewController == NULL) {
        ofxiOSGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT );   //-- default portait orientation.

        m_ofViewController =
        [[ofxiOSViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds]
                                             app:(new Trailze::ofAppMap())];
    }

    ++m_refCount;
}

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if (m_ofViewController.parentViewController != self) {

        if (m_ofViewController.parentViewController != nil) {
            [m_ofViewController.view removeFromSuperview];
            [m_ofViewController removeFromParentViewController];
        }

        [self addChildViewController:m_ofViewController];
        [self.view insertSubview:m_ofViewController.view atIndex:0];
    }
}

-(void) dealloc {

    if (self == m_ofViewController.parentViewController) {
        [m_ofViewController.view removeFromSuperview];
        [m_ofViewController removeFromParentViewController];
    }

    --m_refCount;

    if (m_refCount == 0) {
        [m_ofViewController release];
        m_ofViewController = nil;
    }

    [super dealloc];
}

@end

We have two contemplations:

  1. Should GLViewController be included in ofxiOS at all.

  2. Should we add a mechanism to notify ofApp on changing activities/view controllers or let consumers add such a mechanism in the application level.

Our opinion is:

  1. No, it shouldn’t. In Android we had no choice but to change OF, but since iOS natively supports this, anyone can implement this pattern or variations on it (for example, having the canvas be hanged on a place holder sub view instead of the root view).

  2. I’m not sure there’s any point for such a mechanism. In our project we have a messaging system between the java and cpp code that abstracts and simplifies jni calls. And making a call between your view controller and ofApp in iOS is trivial. We believe that any project complicated enough to have multiple activities/view controllers will have some sort of way to convey the information to the ofApp and change what is being rendered, so there’s no reason to add it directly in OF. It just dirties the interface for no reason.

So that’s our opinion, but I have no problem in adding (1) or (2) or both if anyone deems it worthy.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Android multiple-activities work in pull request 5219 and the iOS GLViewController example in this issue. Then inspect the ofxiOS view-controller entry points to determine whether framework changes are needed or application-level nesting is sufficient. Done means reaching and documenting a decision on framework inclusion and activity/view-controller notifications.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ios, objective-c
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.