Skip to content

Instantly share code, notes, and snippets.

@akaila
Created July 31, 2015 20:36
Show Gist options
  • Save akaila/e11131eb744a0c8f80f0 to your computer and use it in GitHub Desktop.
Save akaila/e11131eb744a0c8f80f0 to your computer and use it in GitHub Desktop.
//React/Views/RCTViewSnapshotManager.h
//
// RCTViewSnapshot.h
// React
//
// Created by Kaila, Ashish on 7/30/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RCTViewManager.h"
@interface RCTViewSnapshotManager : RCTViewManager
@property (nonatomic, strong) NSNumber* sourceViewRef;
@end
React/Views/RCTViewSnapshotManager.m
//
// RCTViewSnapshot.m
// React
//
// Created by Kaila, Ashish on 7/30/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RCTViewSnapshotManager.h"
#import "RCTUIManager.h"
@implementation RCTViewSnapshotManager
RCT_EXPORT_MODULE()
@synthesize bridge = _bridge;
@synthesize methodQueue = _methodQueue;
- (UIView *)view
{
UIView* sourceView;
if ((!self.bridge) || (!(sourceView = [self.bridge.uiManager viewForReactTag:self.sourceViewRef]))) {
return [super view];
}
UIView* snapshot = [sourceView snapshotViewAfterScreenUpdates:NO];
snapshot.frame = sourceView.bounds;
return snapshot;
}
RCT_EXPORT_VIEW_PROPERTY(sourceViewRef, NSNumber)
@end
//Lbraries/react-native/react-native.js
SegmentedControlIOS: require('SegmentedControlIOS'),
SliderIOS: require('SliderIOS'),
SwitchIOS: require('SwitchIOS'),
+ SnapshotView: require('SnapshotView'),
TabBarIOS: require('TabBarIOS'),
Text: require('Text'),
TextInput: require('TextInput'),
//Libraries/Components/SnapshotView/SnapshotView.js
"use strict";
var React = require("React");
var requireNativeComponent = require("requireNativeComponent");
class SnapshotView extends React.Component {
render() {
return <RCTViewSnapshot {...this.props} />;
}
}
SnapshotView.propTypes = {
/**
* Reference tag of the source view that is to be snapshot
*/
sourceViewRef: React.PropTypes.number,
};
var RCTViewSnapshot = requireNativeComponent("RCTViewSnapshot", SnapshotView);
module.exports = SnapshotView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment