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

fix(ios): resolve hot reload issue #4024

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion driver/js/src/modules/contextify_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ void ContextifyModule::LoadUntrustedContent(CallbackInfo& info, void* data) {
try_catch->SetVerbose(true);
string_view view_code(reinterpret_cast<const string_view::char8_t_ *>(move_code.c_str()), move_code.length());
scope->RunJS(view_code, uri, file_name);
ctx->SetProperty(global_object, cur_dir_key, last_dir_str_obj, hippy::napi::PropertyAttribute::ReadOnly);
if (last_dir_str_obj) {
ctx->SetProperty(global_object, cur_dir_key, last_dir_str_obj, hippy::napi::PropertyAttribute::ReadOnly);
}
if (try_catch->HasCaught()) {
error = try_catch->Exception();
FOOTSTONE_DLOG(ERROR) << "RequestUntrustedContent error = " << try_catch->GetExceptionMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
E54E76502FD6AF687683BA8A /* HippyPageCacheContainerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HippyPageCacheContainerView.h; sourceTree = "<group>"; };
EEE0C5F943248577555BFB26 /* SettingsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = "<group>"; };
EF558AABDC113B410B8ED69C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
F3C3E83580FEFC6EEE4CF186 /* DemoConfigs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoConfigs.h; sourceTree = "<group>"; };
FBB045A62B4E511674BF590C /* PageCreationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageCreationViewController.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -131,7 +130,6 @@
6094F1F80FD70F9F9853EE15 /* AppDelegate.m */,
427F60D1B98DA953328F4E71 /* DemoBaseViewController.h */,
4708C41E8571123282E2B806 /* DemoBaseViewController.m */,
F3C3E83580FEFC6EEE4CF186 /* DemoConfigs.h */,
80D715362B1A0B0DCEAA813D /* DemoNavigationViewController.h */,
16348E2DEBFF10ADD6FCF7A9 /* DemoNavigationViewController.m */,
6045C301C6CFDC6C2E87AA66 /* IconUtils.h */,
Expand Down
8 changes: 0 additions & 8 deletions framework/examples/ios-demo/HippyDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
#import "HomePageViewController.h"
#import "DemoNavigationViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand All @@ -40,8 +36,4 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

//- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
// return UIInterfaceOrientationMaskPortrait;
//}

@end
14 changes: 0 additions & 14 deletions framework/examples/ios-demo/HippyDemo/DemoConfigs.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#import "HippyDemoViewController.h"
#import "UIViewController+Title.h"
#import "HippyPageCache.h"
#import "DemoConfigs.h"

#import <hippy/HippyBridge.h>
#import <hippy/HippyRootView.h>
Expand Down
6 changes: 0 additions & 6 deletions framework/ios/base/bridge/HippyBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@
#include <memory>

class VFSUriLoader;
class NativeRenderManager;

namespace hippy {
inline namespace dom {
class DomManager;
class RootNode;
class RenderManager;
};
};


@protocol HippyBridgeInternal <NSObject>

/// The C++ version of RenderManager instance, bridge holds
/// One NativeRenderManager holds multiple Uimanager instance.
@property (nonatomic, assign) std::shared_ptr<NativeRenderManager> renderManager;

/// URI Loader
@property (nonatomic, assign) std::weak_ptr<VFSUriLoader> vfsUriLoader;

Expand Down
14 changes: 10 additions & 4 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ @interface HippyBridge() {
std::shared_ptr<VFSUriLoader> _uriLoader;
std::shared_ptr<hippy::RootNode> _rootNode;

// The C++ version of RenderManager instance, bridge holds,
// One NativeRenderManager holds multiple UIManager instance.
std::shared_ptr<NativeRenderManager> _renderManager;

// 缓存的设备信息
NSDictionary *_cachedDeviceInfo;
}
Expand All @@ -184,7 +188,6 @@ @interface HippyBridge() {

@implementation HippyBridge

@synthesize renderManager = _renderManager;
@synthesize imageLoader = _imageLoader;
@synthesize imageProviders = _imageProviders;
@synthesize startTime = _startTime;
Expand Down Expand Up @@ -259,12 +262,13 @@ - (void)dealloc {
self.invalidateReason = HippyInvalidateReasonDealloc;
[self invalidate];

// FIXME: 检查问题
if (_uriLoader) {
_uriLoader->Terminate();
}
if (_rootNode) {
if (_renderManager) {
_renderManager->RemoveVSyncEventListener(_rootNode);
}
if (_rootNode) {
_rootNode->ReleaseResources();
}
}
Expand Down Expand Up @@ -646,7 +650,9 @@ - (void)unloadInstanceForRootView:(NSNumber *)rootTag {
if (auto scope = self.javaScriptExecutor.pScope) {
scope->UnloadInstance(domValue);
}
_renderManager->UnregisterRootView([rootTag intValue]);
if (_renderManager) {
_renderManager->UnregisterRootView([rootTag intValue]);
}
if (_rootNode) {
_rootNode->ReleaseResources();
_rootNode = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion modules/vfs/ios/VFSUriHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static bool CheckRequestFromCPP(const std::unordered_map<std::string, std::strin
if (!url) {
return nil;
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setAllHTTPHeaderFields:HttpHeadersFromMap(headers)];
return [request copy];
}
Expand Down
10 changes: 5 additions & 5 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ - (void)registerRootView:(UIView *)rootView asRootNode:(std::weak_ptr<RootNode>)
AssertMainQueue();

NSNumber *hippyTag = rootView.hippyTag;
NSAssert(HippyIsHippyRootView(hippyTag), @"View %@ with tag #%@ is not a root view", rootView, hippyTag);

#if HIPPY_DEBUG
NSAssert(![_viewRegistry containRootComponentWithTag:hippyTag], @"RootView Tag already exists. Added %@ twice", hippyTag);
#endif
HippyAssert(HippyIsHippyRootView(hippyTag), @"View %@ with tag #%@ is not a root view", rootView, hippyTag);
if ([_viewRegistry containRootComponentWithTag:hippyTag]) {
HippyLogWarn(@"RootView Tag %@ already exists. Start Replace!", hippyTag);
[self unregisterRootViewFromTag:hippyTag];
}

// Register view
[_viewRegistry addRootComponent:rootView rootNode:rootNode forTag:hippyTag];
Expand Down
3 changes: 2 additions & 1 deletion renderer/native/ios/renderer/NativeRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <memory>
#include <vector>
#include <shared_mutex>
#include <unordered_map>
#include "dom/render_manager.h"

Expand Down Expand Up @@ -157,7 +158,7 @@ class NativeRenderManager : public hippy::RenderManager, public std::enable_shar
void UnregisterRootView(uint32_t id);

private:

std::shared_mutex _mutex; // For _uiManagerMap's thread safety
std::unordered_map<uint32_t, HippyUIManager *> _uiManagerMap;
};

Expand Down
26 changes: 15 additions & 11 deletions renderer/native/ios/renderer/NativeRenderManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
@autoreleasepool {
auto rootNode = root_node.lock();
if (rootNode) {
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager createRenderNodes:std::move(nodes) onRootNode:root_node];
}
}
Expand All @@ -59,8 +59,8 @@
@autoreleasepool {
auto rootNode = root_node.lock();
if (rootNode) {
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager updateRenderNodes:std::move(nodes) onRootNode:root_node];
}

Expand All @@ -72,8 +72,8 @@
@autoreleasepool {
auto rootNode = root_node.lock();
if (rootNode) {
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager deleteRenderNodesIds:std::move(nodes) onRootNode:root_node];
}
}
Expand All @@ -86,8 +86,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
using DomNodeUpdateInfoTuple = std::tuple<int32_t, hippy::LayoutResult>;
std::vector<DomNodeUpdateInfoTuple> nodes_infos;
nodes_infos.reserve(nodes.size());
Expand All @@ -111,8 +111,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager renderMoveViews:std::move(moved_ids)
fromContainer:from_pid
toContainer:to_pid
Expand All @@ -128,8 +128,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
// Check whether all nodes have the same pid
uint32_t firstPid = nodes[0]->GetPid();
bool allSamePid = std::all_of(nodes.begin(), nodes.end(),
Expand Down Expand Up @@ -160,8 +160,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager batchOnRootNode:root_node];
TDF_PERF_LOG("NativeRenderManager::EndBatch End");

Expand All @@ -182,8 +182,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
auto node = dom_node.lock();
if (node) {
int32_t tag = node->GetId();
Expand All @@ -200,8 +200,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
auto node = dom_node.lock();
if (node) {
int32_t node_id = node->GetId();
Expand All @@ -216,8 +216,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
[uiManager removeVSyncEventOnRootNode:root_node];
}
}
Expand All @@ -232,8 +232,8 @@
if (!rootNode) {
return;
}
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()];
HippyAssertParam(uiManager);
std::shared_ptr<DomNode> node = dom_node.lock();
if (node) {
HippyValue hippy_value;
Expand All @@ -258,13 +258,15 @@
return;
}
HippyAssertParam(uiManager);
std::shared_lock<std::shared_mutex> lock(_mutex);
_uiManagerMap[rootNode->GetId()] = uiManager;
[uiManager registerRootView:view asRootNode:root_node];
}
}

void NativeRenderManager::UnregisterRootView(uint32_t rootId) {
@autoreleasepool {
std::shared_lock<std::shared_mutex> lock(_mutex);
HippyUIManager *uiManager = _uiManagerMap[rootId];
HippyAssertParam(uiManager);
[uiManager unregisterRootViewFromTag:@(rootId)];
Expand All @@ -273,9 +275,11 @@
}

NativeRenderManager::~NativeRenderManager() {
std::shared_lock<std::shared_mutex> lock(_mutex);
for (auto &pair : _uiManagerMap) {
[pair.second invalidate];
}
_uiManagerMap.clear();
FOOTSTONE_LOG(INFO) << "~NativeRenderManager";
}

Loading