Files
react-native/RNTester/js/SnapshotViewIOS.ios.js
James Munro 794da6a4e4 Remove SnapshotViewIOS from public interface (#23497)
Summary:
Part of Lean Core #23313

Removes `SnapshotViewIOS` from the public RN interface.

I think there's a wider discussion to be had here about whether `RCTTest` should be part of the public distribution or at least whether this should be split into a separate utils package. It's mainly used by the RNTester app. It seems to be little known about but there are [some references to it online](https://blog.callstack.io/testing-your-react-native-apps-abfe41903dfd).

[iOS] [Removed] - `SnapshotViewIOS` is no longer publicly exported from RN
Pull Request resolved: https://github.com/facebook/react-native/pull/23497

Differential Revision: D14123280

Pulled By: cpojer

fbshipit-source-id: badaf6cb5d2195268f0f8b429fc11d6525747708
2019-02-18 04:04:23 -08:00

69 lines
1.7 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const React = require('React');
const StyleSheet = require('StyleSheet');
const UIManager = require('UIManager');
const View = require('View');
const {TestModule} = require('NativeModules');
import type {SyntheticEvent} from 'CoreEventTypes';
import type {ViewProps} from 'ViewPropTypes';
// Verify that RCTSnapshot is part of the UIManager since it is only loaded
// if you have linked against RCTTest like in tests, otherwise we will have
// a warning printed out
const RCTSnapshot = UIManager.getViewManagerConfig('RCTSnapshot')
? require('RCTSnapshotNativeComponent')
: View;
type SnapshotReadyEvent = SyntheticEvent<
$ReadOnly<{
testIdentifier: string,
}>,
>;
type Props = $ReadOnly<{|
...ViewProps,
onSnapshotReady?: ?(event: SnapshotReadyEvent) => mixed,
testIdentifier?: ?string,
|}>;
class SnapshotViewIOS extends React.Component<Props> {
onDefaultAction = (event: SnapshotReadyEvent) => {
TestModule.verifySnapshot(TestModule.markTestPassed);
};
render() {
const testIdentifier = this.props.testIdentifier || 'test';
const onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction;
return (
// $FlowFixMe - Typing ReactNativeComponent revealed errors
<RCTSnapshot
style={style.snapshot}
{...this.props}
onSnapshotReady={onSnapshotReady}
testIdentifier={testIdentifier}
/>
);
}
}
const style = StyleSheet.create({
snapshot: {
flex: 1,
},
});
module.exports = SnapshotViewIOS;