-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SnapshotView which wraps Renderable content and will verify…
… the snapshot Reviewed By: @javache Differential Revision: D2493722
- Loading branch information
Dave Miller
authored and
facebook-github-bot-3
committed
Oct 2, 2015
1 parent
de73622
commit b8c42f7
Showing
6 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTViewManager.h" | ||
|
||
@interface RCTSnapshotManager : RCTViewManager | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTSnapshotManager.h" | ||
|
||
@interface RCTSnapshotView : UIView | ||
|
||
@property (nonatomic, copy) RCTDirectEventBlock onSnapshotReady; | ||
@property (nonatomic, copy) NSString *testIdentifier; | ||
|
||
@end | ||
|
||
@implementation RCTSnapshotView | ||
|
||
- (void)setTestIdentifier:(NSString *)testIdentifier | ||
{ | ||
if (![_testIdentifier isEqualToString:testIdentifier]) { | ||
_testIdentifier = [testIdentifier copy]; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if (self.onSnapshotReady) { | ||
self.onSnapshotReady(@{@"testIdentifier" : self.testIdentifier}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation RCTSnapshotManager | ||
|
||
RCT_EXPORT_MODULE() | ||
|
||
- (UIView *)view { | ||
return [RCTSnapshotView new]; | ||
} | ||
|
||
RCT_EXPORT_VIEW_PROPERTY(testIdentifier, NSString) | ||
RCT_EXPORT_VIEW_PROPERTY(onSnapshotReady, RCTDirectEventBlock) | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule SnapshotView | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
var React = require('React'); | ||
var StyleSheet = require('StyleSheet'); | ||
var { TestModule } = require('NativeModules'); | ||
|
||
var requireNativeComponent = require('requireNativeComponent'); | ||
|
||
var SnapshotView = React.createClass({ | ||
onDefaultAction: function(event: Object) { | ||
TestModule.verifySnapshot(TestModule.markTestPassed); | ||
}, | ||
|
||
render: function() { | ||
var testIdentifier = this.props.testIdentifier || 'test'; | ||
var onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction; | ||
return ( | ||
<RCTSnapshot | ||
style={style.snapshot} | ||
{...this.props} | ||
onSnapshotReady={onSnapshotReady} | ||
testIdentifier={testIdentifier} | ||
/> | ||
); | ||
}, | ||
|
||
propTypes: { | ||
// A callback when the Snapshot view is ready to be compared | ||
onSnapshotReady : React.PropTypes.func, | ||
// A name to identify the individual instance to the SnapshotView | ||
testIdentifier : React.PropTypes.string, | ||
} | ||
}); | ||
|
||
var style = StyleSheet.create({ | ||
snapshot: { | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
var RCTSnapshot = requireNativeComponent('RCTSnapshot', SnapshotView); | ||
|
||
module.exports = SnapshotView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters