Permalink
Browse files

Added TUIAnimationManager, to forcibly disable implicit AppKit animat…

…ions
  • Loading branch information...
1 parent 6616ea1 commit 36c8c385c3894a376f94bfc33bee8cde10e1a456 @jspahrsummers jspahrsummers committed Jul 18, 2012
Showing with 145 additions and 0 deletions.
  1. +10 −0 TwUI.xcodeproj/project.pbxproj
  2. +23 −0 lib/Support/TUIAnimationManager.h
  3. +112 −0 lib/Support/TUIAnimationManager.m
@@ -266,6 +266,9 @@
CBB74CE513BE6E1900C85CB5 /* TUIViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C8E13BE6E1900C85CB5 /* TUIViewController.m */; };
CBB74CE613BE6E1900C85CB5 /* TUIViewNSViewContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C8F13BE6E1900C85CB5 /* TUIViewNSViewContainer.h */; settings = {ATTRIBUTES = (Public, ); }; };
CBB74CE713BE6E1900C85CB5 /* TUIViewNSViewContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C9013BE6E1900C85CB5 /* TUIViewNSViewContainer.m */; };
+ D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
+ D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
+ D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
D0C764EB15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0C764EC15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0C764ED15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -460,6 +463,8 @@
CBB74C8E13BE6E1900C85CB5 /* TUIViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIViewController.m; sourceTree = "<group>"; };
CBB74C8F13BE6E1900C85CB5 /* TUIViewNSViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIViewNSViewContainer.h; sourceTree = "<group>"; };
CBB74C9013BE6E1900C85CB5 /* TUIViewNSViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIViewNSViewContainer.m; sourceTree = "<group>"; };
+ D040610815B6A77500F753ED /* TUIAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIAnimationManager.h; sourceTree = "<group>"; };
+ D040610915B6A77500F753ED /* TUIAnimationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIAnimationManager.m; sourceTree = "<group>"; };
D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIBridgedView.h; sourceTree = "<group>"; };
D0C7650415B6156A00E7AC2C /* TUIHostView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIHostView.h; sourceTree = "<group>"; };
D0C7650C15B6189D00E7AC2C /* TUINSHostView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUINSHostView.h; sourceTree = "<group>"; };
@@ -633,6 +638,8 @@
D0C7652115B6232100E7AC2C /* CALayer+TUIExtensions.m */,
D0C7652215B6232100E7AC2C /* CATransaction+TUIExtensions.h */,
D0C7652315B6232100E7AC2C /* CATransaction+TUIExtensions.m */,
+ D040610815B6A77500F753ED /* TUIAnimationManager.h */,
+ D040610915B6A77500F753ED /* TUIAnimationManager.m */,
D0C7656F15B6341800E7AC2C /* TUICAAction.h */,
D0C7657015B6341800E7AC2C /* TUICAAction.m */,
);
@@ -1099,6 +1106,7 @@
D0C7656215B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */,
D0C7656815B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657615B6341800E7AC2C /* TUICAAction.m in Sources */,
+ D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1173,6 +1181,7 @@
D0C7656015B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */,
D0C7656615B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657415B6341800E7AC2C /* TUICAAction.m in Sources */,
+ D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1253,6 +1262,7 @@
D0C7656115B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */,
D0C7656715B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657515B6341800E7AC2C /* TUICAAction.m in Sources */,
+ D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,23 @@
+//
+// TUIAnimationManager.h
+//
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+/**
+ * This private class is responsible for disabling implicit NSView animations.
+ *
+ * This class may be expanded in the future to add other global animation
+ * capabilities.
+ */
+@interface TUIAnimationManager : NSObject
+
+/*
+ * Returns the singleton instance of this class.
+ */
++ (TUIAnimationManager *)defaultManager;
+
+@end
@@ -0,0 +1,112 @@
+//
+// TUIAnimationManager.m
+//
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
+//
+
+#import "TUIAnimationManager.h"
+
+/**
+ * Disables implicit AppKit animations on every run loop iteration.
+ */
+static void mainRunLoopObserverCallback (CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
+ [[NSAnimationContext currentContext] setDuration:0];
+}
+
+@interface TUIAnimationManager ()
+/**
+ * The observer associated with the main run loop, responsible for invoking the
+ * mainRunLoopObserverCallback.
+ */
+@property (nonatomic) CFRunLoopObserverRef mainRunLoopObserver;
+
+/**
+ * Invoked on the defaultManager when the application has finished launching.
+ */
+- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification;
+
+/**
+ * Registers an observer on the main run loop which will invoke the
+ * mainRunLoopObserverCallback.
+ */
+- (void)registerRunLoopObserver;
+@end
+
+@implementation TUIAnimationManager
+
+#pragma mark Properties
+
+@synthesize mainRunLoopObserver = m_mainRunLoopObserver;
+
+- (void)setMainRunLoopObserver:(CFRunLoopObserverRef)observer {
+ if (observer == m_mainRunLoopObserver)
+ return;
+
+ if (m_mainRunLoopObserver) {
+ CFRunLoopRemoveObserver(CFRunLoopGetMain(), m_mainRunLoopObserver, kCFRunLoopCommonModes);
+ CFRelease(m_mainRunLoopObserver);
+ }
+
+ if (observer)
+ CFRetain(observer);
+
+ m_mainRunLoopObserver = observer;
+}
+
+#pragma mark Lifecycle
+
++ (void)load {
+ [[NSNotificationCenter defaultCenter]
+ addObserver:[self defaultManager]
+ selector:@selector(applicationDidFinishLaunchingNotification:)
+ name:NSApplicationDidFinishLaunchingNotification
+ object:nil
+ ];
+}
+
++ (TUIAnimationManager *)defaultManager; {
+ static id singleton = nil;
+ static dispatch_once_t pred;
+
+ dispatch_once(&pred, ^{
+ singleton = [[self alloc] init];
+ });
+
+ return singleton;
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ self.mainRunLoopObserver = NULL;
+}
+
+#pragma mark Run Loop Observer
+
+- (void)registerRunLoopObserver; {
+ // set up an observer on the main run loop that can disable implicit
+ // animations
+ CFRunLoopObserverRef observer = CFRunLoopObserverCreate(
+ NULL,
+ kCFRunLoopBeforeTimers,
+ YES,
+ 10000,
+ &mainRunLoopObserverCallback,
+ NULL
+ );
+
+ CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
+
+ self.mainRunLoopObserver = observer;
+ CFRelease(observer);
+}
+
+#pragma mark Notifications
+
+- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification; {
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:notification.name object:nil];
+ [self registerRunLoopObserver];
+}
+
+@end

0 comments on commit 36c8c38

Please sign in to comment.