2015-10-02 22:13:48 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-10-02 22:13:48 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-10-02 22:13:48 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2015-10-02 22:13:48 +03:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2015-10-02 22:13:48 +03:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-10 20:15:13 +03:00
|
|
|
const React = require('react');
|
|
|
|
const {NativeModules, StyleSheet, UIManager, View} = require('react-native');
|
2015-10-02 22:13:48 +03:00
|
|
|
|
2019-04-10 20:15:13 +03:00
|
|
|
const {TestModule} = NativeModules;
|
2018-08-23 04:22:00 +03:00
|
|
|
|
2019-04-10 20:15:13 +03:00
|
|
|
import type {SyntheticEvent} from '../../Libraries/Types/CoreEventTypes';
|
|
|
|
import type {ViewProps} from '../../Libraries/Components/View/ViewPropTypes';
|
2018-09-24 20:55:30 +03:00
|
|
|
|
2018-06-01 22:37:22 +03:00
|
|
|
// 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
|
2018-09-28 01:55:31 +03:00
|
|
|
const RCTSnapshot = UIManager.getViewManagerConfig('RCTSnapshot')
|
2019-04-10 20:15:13 +03:00
|
|
|
? require('../RCTTest/RCTSnapshotNativeComponent')
|
2018-06-01 22:37:22 +03:00
|
|
|
: View;
|
|
|
|
|
2018-09-24 20:55:30 +03:00
|
|
|
type SnapshotReadyEvent = SyntheticEvent<
|
|
|
|
$ReadOnly<{
|
|
|
|
testIdentifier: string,
|
|
|
|
}>,
|
|
|
|
>;
|
|
|
|
|
|
|
|
type Props = $ReadOnly<{|
|
|
|
|
...ViewProps,
|
|
|
|
onSnapshotReady?: ?(event: SnapshotReadyEvent) => mixed,
|
|
|
|
testIdentifier?: ?string,
|
|
|
|
|}>;
|
2016-07-26 11:00:02 +03:00
|
|
|
|
2018-09-24 20:55:30 +03:00
|
|
|
class SnapshotViewIOS extends React.Component<Props> {
|
|
|
|
onDefaultAction = (event: SnapshotReadyEvent) => {
|
2015-10-02 22:13:48 +03:00
|
|
|
TestModule.verifySnapshot(TestModule.markTestPassed);
|
2016-07-26 11:00:02 +03:00
|
|
|
};
|
2015-10-02 22:13:48 +03:00
|
|
|
|
2016-07-26 11:00:02 +03:00
|
|
|
render() {
|
2018-05-11 01:44:52 +03:00
|
|
|
const testIdentifier = this.props.testIdentifier || 'test';
|
|
|
|
const onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction;
|
2015-10-02 22:13:48 +03:00
|
|
|
return (
|
2018-05-13 10:48:51 +03:00
|
|
|
// $FlowFixMe - Typing ReactNativeComponent revealed errors
|
2015-10-02 22:13:48 +03:00
|
|
|
<RCTSnapshot
|
|
|
|
style={style.snapshot}
|
|
|
|
{...this.props}
|
|
|
|
onSnapshotReady={onSnapshotReady}
|
|
|
|
testIdentifier={testIdentifier}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 11:00:02 +03:00
|
|
|
}
|
2015-10-02 22:13:48 +03:00
|
|
|
|
2018-05-11 01:44:52 +03:00
|
|
|
const style = StyleSheet.create({
|
2015-10-02 22:13:48 +03:00
|
|
|
snapshot: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-10-13 21:02:35 +03:00
|
|
|
module.exports = SnapshotViewIOS;
|