Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于FBFlutterViewContainer作为UITabbarController的viewcontrollers #2134

Open
kavin-zhihua opened this issue Sep 11, 2024 · 0 comments
Open
Labels
iOS iOS Only

Comments

@kavin-zhihua
Copy link

kavin-zhihua commented Sep 11, 2024

请描述遇到的问题,以及您所期望的正确的结果

FBFlutterViewContainer 每多一个,就会有60M内存开销,我现在的原生UITabbarController中嵌的全部是flutter的FBFlutterViewContainer,我希望只有一份内存开销,比如我有5个FBFlutterViewContainer作为UITabbarcontroller的viewcontrollers,只有一份开销。

请说明如何操作会遇到上述问题

官方demo中关键代码位置:如果这个地方有很多个FBFlutterViewContainer,开销非常大
FBFlutterViewContainer *fvc = [[FBFlutterViewContainer alloc] init] ;
[fvc setName:@"tab_friend" uniqueId:nil params:@{} opaque:YES];
fvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"flutter_tab" image:nil tag:1];
UITabBarController *tabVC = [[UITabBarController alloc] init];
tabVC.viewControllers = @[vc,fvc];

在下面填入关键复现代码

//
// AppDelegate.m
// sdfsdf
//
// Created by Jidong Chen on 2018/10/18.
// Copyright © 2018年 Jidong Chen. All rights reserved.
//

#import "AppDelegate.h"
#import "FLNativeView.h"
#import "UIViewControllerDemo.h"
#import "NativeViewController.h"
#import "MyFlutterBoostDelegate.h"

#import <flutter_boost/FlutterBoost.h>

@interface AppDelegate ()

@EnD

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];

    FlutterBoostSetupOptions* options = [FlutterBoostSetupOptions createDefault];
    options.dartEntryPointArgs = @[ @"I'm from IOS!", @"--for-test" ];

    MyFlutterBoostDelegate* delegate=[[MyFlutterBoostDelegate alloc ] init];
    [[FlutterBoost instance] setup:application delegate:delegate callback:^(FlutterEngine engine) {
    NSObject
    registrar = [engine registrarForPlugin:@"plugin-name"];
    FLNativeViewFactory* factory = [[FLNativeViewFactory alloc] initWithMessenger:registrar.messenger];
    [[engine registrarForPlugin:@""] registerViewFactory:factory withId:@""];
    } options:options];

    UIViewControllerDemo *vc = [[UIViewControllerDemo alloc] initWithNibName:@"UIViewControllerDemo" bundle:[NSBundle mainBundle]];
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"hybrid" image:nil tag:0];

    FBFlutterViewContainer *fvc = [[FBFlutterViewContainer alloc] init] ;

    [fvc setName:@"tab_friend" uniqueId:nil params:@{} opaque:YES];
    fvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"flutter_tab" image:nil tag:1];

    UITabBarController *tabVC = [[UITabBarController alloc] init];
    tabVC.viewControllers = @[vc,fvc];

    UINavigationController *rvc = [[UINavigationController alloc] initWithRootViewController:tabVC];

    delegate.navigationController=rvc;

    self.window.rootViewController = rvc;

    UIButton *nativeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    nativeButton.frame = CGRectMake(self.window.frame.size.width * 0.5 - 50, 200, 100, 40);
    nativeButton.backgroundColor = [UIColor redColor];
    [nativeButton setTitle:@"push native" forState:UIControlStateNormal];
    [nativeButton addTarget:self action:@selector(pushNative) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:nativeButton];

    UIButton *pushEmbeded = [UIButton buttonWithType:UIButtonTypeCustom];
    pushEmbeded.frame = CGRectMake(self.window.frame.size.width * 0.5 - 70, 150, 140, 40);
    pushEmbeded.backgroundColor = [UIColor redColor];
    [pushEmbeded setTitle:@"push embedded" forState:UIControlStateNormal];
    [pushEmbeded addTarget:self action:@selector(pushEmbeded) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:pushEmbeded];

    return YES;
    }

  • (void)pushNative
    {
    UINavigationController *nvc = (id)self.window.rootViewController;
    UIViewControllerDemo *vc = [[UIViewControllerDemo alloc] initWithNibName:@"UIViewControllerDemo" bundle:[NSBundle mainBundle]];
    [nvc pushViewController:vc animated:YES];
    }
    //

  • (void)pushEmbeded
    {
    UINavigationController *nvc = (id)self.window.rootViewController;
    UIViewController *vc = [[NativeViewController alloc] init];
    [nvc pushViewController:vc animated:YES];
    }

  • (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

  • (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

  • (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

  • (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

  • (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

复现的平台

iOS

Flutter SDK版本

3.13.5

FlutterBoost版本

4.4.1

是否延迟初始化FlutterBoost

No

解决方案

求各位大大们支支招

@kavin-zhihua kavin-zhihua changed the title 关于FBFlutterViewContainer作为UITabbarController的viewcontrollers, 关于FBFlutterViewContainer作为UITabbarController的viewcontrollers Sep 11, 2024
@joechan-cq joechan-cq added the iOS iOS Only label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS iOS Only
Projects
None yet
Development

No branches or pull requests

2 participants