Skip to content

Commit 246f7d8

Browse files
committed
Merge branch 'respondsToLiveResizing'
2 parents 108e323 + 307ada7 commit 246f7d8

File tree

10 files changed

+43
-16
lines changed

10 files changed

+43
-16
lines changed

Examples/UIExplorer/UIExplorerApp.osx.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var {
2626
View,
2727
Text,
2828
Dimensions,
29-
TouchableHighlight
3029
} = ReactNative;
3130

3231
var defaultLayout = Dimensions.get('window');
@@ -48,7 +47,7 @@ class UIExplorerApp extends React.Component {
4847
<View style={[styles.leftPanel, {width: 300}]}>
4948
<UIExplorerList openExample={(component) => this.setState({component})}/>
5049
</View>
51-
<View style={[styles.rightPanel, {width: this.state.layout.width - 300}]}>
50+
<View style={[styles.rightPanel, {width: this.state.layout.width - 300}]} respondsToLiveResizing>
5251
{this.state.component && <Component />}
5352
</View>
5453
</View>
@@ -69,7 +68,7 @@ class Welcome extends React.Component {
6968
var styles = StyleSheet.create({
7069
container: {
7170
flex: 1,
72-
flexDirection: 'row'
71+
flexDirection: 'row',
7372
},
7473
itemWrapper: {
7574
backgroundColor: '#eaeaea',

Libraries/Components/View/View.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ const View = React.createClass({
284284
*/
285285
removeClippedSubviews: PropTypes.bool,
286286

287+
/**
288+
* Workaround until we have not found the way to solve the resizing issue
289+
*/
290+
respondsToLiveResizing: PropTypes.bool,
291+
287292
/**
288293
* Whether this view should render itself (and all of its children) into a
289294
* single hardware texture on the GPU.

React/Base/RCTDisplayLink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (instancetype)init
3131
if ((self = [super init])) {
3232
_frameUpdateObservers = [NSMutableSet new];
3333
_jsTimer = [NSTimer
34-
timerWithTimeInterval:0.01
34+
timerWithTimeInterval:0.025
3535
target:self
3636
selector:@selector(_jsThreadUpdate:)
3737
userInfo:nil

React/Base/RCTRootView.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
6868

6969
// TODO: Turn on layer backing just to avoid https://github.com/ptmt/react-native-desktop/issues/47
7070
// Maybe we could turn it off after the bug fixed in the future.
71-
[self setWantsLayer:YES];
71+
if (([self window].styleMask & NSFullSizeContentViewWindowMask) != NSFullSizeContentViewWindowMask) {
72+
[self setWantsLayer:YES];
73+
}
7274

7375
[self setNeedsLayout:NO];
7476
[self setMaterial:NSVisualEffectMaterialLight];
@@ -313,6 +315,7 @@ @implementation RCTRootContentView
313315
__weak RCTBridge *_bridge;
314316
RCTTouchHandler *_touchHandler;
315317
NSColor *_backgroundColor;
318+
CFTimeInterval _lastResizingAt;
316319
}
317320

318321
- (instancetype)initWithFrame:(CGRect)frame
@@ -321,6 +324,7 @@ - (instancetype)initWithFrame:(CGRect)frame
321324
{
322325
if ((self = [super initWithFrame:frame])) {
323326
_bridge = bridge;
327+
_lastResizingAt = CACurrentMediaTime();
324328
self.reactTag = reactTag;
325329
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
326330
[self addGestureRecognizer:_touchHandler];
@@ -367,25 +371,28 @@ - (void)mouseExited:(__unused NSEvent *)theEvent
367371
[[self window] setAcceptsMouseMovedEvents:NO];
368372
}
369373

370-
// TODO: fire onLayout or something?
371-
//- (void)viewDidEndLiveResize
372-
//{
373-
// [self setFrame:[RCTSharedApplication() mainWindow].contentView.frame];
374-
//}
374+
- (void)viewDidEndLiveResize
375+
{
376+
[super viewDidEndLiveResize];
377+
[_bridge.uiManager setFrame:self.frame forView:self];
378+
}
375379

376380
- (void)setFrame:(CGRect)frame
377381
{
378382
super.frame = frame;
379383
if (self.reactTag && _bridge.isValid) {
380-
[_bridge.uiManager setFrame:frame forView:self];
384+
if (!self.inLiveResize || (self.inLiveResize && (CACurrentMediaTime() - _lastResizingAt) > 0.026)) {
385+
[_bridge.uiManager setFrame:frame forView:self];
386+
_lastResizingAt = CACurrentMediaTime();
387+
}
381388
}
382389
}
383390

384391
- (void)setBackgroundColor:(NSColor *)backgroundColor
385392
{
386393
_backgroundColor = backgroundColor;
387394
if (self.reactTag && _bridge.isValid) {
388-
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
395+
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
389396
}
390397
}
391398

React/Modules/RCTUIManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView *
575575

576576
// Animate view creation
577577
if (createAnimation) {
578-
[view reactSetFrame:frame];
578+
//[view reactSetFrame:frame];
579579

580580
CATransform3D finalTransform = view.layer.transform;
581581
CGFloat finalOpacity = view.layer.opacity;
@@ -616,7 +616,7 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView *
616616
// Update without animation
617617
} else {
618618
// Workaround for https://github.com/ptmt/react-native-desktop/issues/47
619-
// Need to speedup layout or make cancelling mechanism
619+
// Need to speedup layout or make a cancelling mechanism
620620
if (!view.isReactRootView) {
621621
[view reactSetFrame:frame];
622622
}

React/Views/NSView+React.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ - (NSView *)reactSuperview
8484

8585
- (void)reactSetFrame:(CGRect)frame
8686
{
87+
// if ([self respondsToSelector:@selector(respondsToLiveResizing)]) {
88+
//
89+
// } else {
90+
// NSLog(@"%@", self.reactTag);
91+
// }
8792
// These frames are in terms of anchorPoint = topLeft, but internally the
8893
// views are anchorPoint = center for easier scale and rotation animations.
8994
// Convert the frame so it works with anchorPoint = center.
@@ -99,8 +104,9 @@ - (void)reactSetFrame:(CGRect)frame
99104
}
100105

101106
self.frame = frame;
107+
102108
// TODO: why position matters? It's only produce bugs
103-
//self.layer.position = position;
109+
// self.layer.position = position;
104110
self.layer.bounds = bounds;
105111
}
106112

React/Views/RCTView.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
*/
5555
@property (nonatomic, assign) BOOL removeClippedSubviews;
5656

57+
/**
58+
* Workaround on a lot of views with layers
59+
*/
60+
@property (nonatomic, assign) BOOL respondsToLiveResizing;
61+
62+
5763
/**
5864
* Hide subviews if they are outside the view bounds.
5965
* This is an optimisation used predominantly with RKScrollViews

React/Views/RCTView.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ - (BOOL)wantsUpdateLayer
530530

531531
- (void)reactSetFrame:(CGRect)frame
532532
{
533+
if (self.inLiveResize && !self.respondsToLiveResizing) {
534+
return;
535+
}
533536
// If frame is zero, or below the threshold where the border radii can
534537
// be rendered as a stretchable image, we'll need to re-render.
535538
// TODO: detect up-front if re-rendering is necessary

React/Views/RCTViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ - (void)checkLayerExists:(NSView *)view
130130
RCT_EXPORT_VIEW_PROPERTY(accessibilityLabel, NSString)
131131
RCT_EXPORT_VIEW_PROPERTY(accessibilityTraits, UIAccessibilityTraits)
132132
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, NSColor)
133+
RCT_EXPORT_VIEW_PROPERTY(respondsToLiveResizing, BOOL)
133134
RCT_REMAP_VIEW_PROPERTY(accessible, accessibilityElement, BOOL)
134135
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier, NSString)
135136
RCT_REMAP_VIEW_PROPERTY(testRole, accessibilityRole, NSString)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-desktop",
3-
"version": "0.6.4",
3+
"version": "0.6.6",
44
"description": "A framework for building native desktop apps using React",
55
"license": "BSD-3-Clause",
66
"repository": {

0 commit comments

Comments
 (0)