Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure to invoke <TUIBridgedView> view hierarchy change methods

  • Loading branch information...
commit af528b2c1956e5224ac14c908690891a0c306ce4 1 parent 47c53c9
@jspahrsummers jspahrsummers authored
Showing with 25 additions and 3 deletions.
  1. +14 −3 lib/UIKit/TUIView+TUIBridgedView.m
  2. +11 −0 lib/UIKit/TUIView.m
View
17 lib/UIKit/TUIView+TUIBridgedView.m
@@ -120,10 +120,21 @@ - (BOOL)pointInside:(CGPoint)point; {
return self.superview;
}
-- (void)setHostView:(id<TUIHostView>)hostView {
- objc_setAssociatedObject(self, @selector(hostView), hostView, OBJC_ASSOCIATION_ASSIGN);
+- (void)setHostView:(id<TUIHostView>)view {
+ @autoreleasepool {
+ TUINSView *oldTUINSView = self.ancestorTUINSView;
+ TUINSView *newTUINSView = view.ancestorTUINSView;
- [self viewHierarchyDidChange];
+ if (oldTUINSView != newTUINSView)
+ [self willMoveToTUINSView:newTUINSView];
+
+ objc_setAssociatedObject(self, @selector(hostView), view, OBJC_ASSOCIATION_ASSIGN);
+
+ if (oldTUINSView != newTUINSView)
+ [self didMoveFromTUINSView:oldTUINSView];
+
+ [self viewHierarchyDidChange];
+ }
}
- (void)ancestorDidLayout; {
View
11 lib/UIKit/TUIView.m
@@ -699,6 +699,9 @@ - (void)removeFromSuperview // everything should go through this
TUIView *superview = [self superview];
if(superview) {
+ TUINSView *nsView = self.ancestorTUINSView;
+ [self willMoveToTUINSView:nil];
+
[superview willRemoveSubview:self];
[self willMoveToSuperview:nil];
@@ -707,6 +710,8 @@ - (void)removeFromSuperview // everything should go through this
self.nsView = nil;
[self didMoveToSuperview];
+ [self didMoveFromTUINSView:nsView];
+ [self viewHierarchyDidChange];
}
}
@@ -764,6 +769,7 @@ - (void)setNextResponder:(NSResponder *)r
}
}
+// TODO: get rid of these macros, and just always go through a single method
#define PRE_ADDSUBVIEW(index) \
if (!_subviews) \
_subviews = [[NSMutableArray alloc] init]; \
@@ -774,12 +780,17 @@ - (void)setNextResponder:(NSResponder *)r
[self.subviews insertObject:view atIndex:index];\
}\
[view removeFromSuperview]; /* will call willAdd:nil and didAdd (nil) */ \
+ \
+ TUINSView *originalNSView_ = view.ancestorTUINSView; \
+ [view willMoveToTUINSView:_nsView]; \
+ \
[view willMoveToSuperview:self]; \
view.nsView = _nsView;
#define POST_ADDSUBVIEW \
[self didAddSubview:view]; \
[view didMoveToSuperview]; \
+ [view didMoveFromTUINSView:originalNSView_]; \
[view setNextResponder:self]; \
[self _blockLayout];
Please sign in to comment.
Something went wrong with that request. Please try again.