Source

containers/Custom/Group/GroupMessagesScreen.ts

import {compose, mapProps} from "recompose";
import {withNavigation} from "../../../components/hocs/withNavigation";
import PropTypes from "prop-types";

import GroupMessage from "../../Group/GroupMessagesScreen";
import withActiveCallBacks from "../../../navigators/react-navigation-addons/withActiveCallBacks";
import withLoadGroup from "../../../components/hocs/withLoadGroup";
import {privacyOptions} from "../../Group/GroupMessageOptionsScreen";

const buildProps = props => {
	const privacyValue = props.screenType === "private" ? "private" : "open";

	const groupMessagePrivacy = privacyOptions.find(
		({value}) => value === privacyValue
	);

	return {
		useModel: false,
		screenKey:
			props.screenType === "private"
				? "privateMessage"
				: "selectedMembersGroupMessage",
		groupMessagePrivacy,
		...props
	};
};

/**
 * You can use this component to display Group Messages Screen in your custom screen.
 * This is can be used to send messages privately or to selected members in the group.
 * @component
 * @example
 * //In custom_code/components/MyCustomScreen.js...
 *
 * import React from 'react';
 * import { View, Text } from 'react-native';
 * import GroupMessagesScreen from "@src/containers/Custom/Group/GroupMessagesScreen";
 *
 * const MyCustomScreen = (props) => (
 *   <GroupMessagesScreen {...props}
 *     groupId={9}
 *     showSearch={false}
 *     hideCancelButton={true}
 *     hideBackButton={true}
 *     screenTitle="Send to Selected"
 *     screenType="private"
 *     LoadingComponent={<View style={{ flex: 1, alignSelf: "center", justifyContent: "center" }}>
 *       <Text>Loading, please wait...</Text>
 *     </View>
 *     } />
 * )
 *
 *
 * export default MyCustomScreen;
 *
 * //In custom_code/index.js...
 * import MyCustomScreen from "./components/MyCustomScreen";
 * export const applyCustomCode = externalCodeSetup => {
 *
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "All"
 *  );
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "Main"
 *  );
 * }
 */

export const GroupMessagesScreen = compose(
	mapProps(buildProps),
	withNavigation,
	withActiveCallBacks,
	withLoadGroup
)(GroupMessage);

export default GroupMessagesScreen;

GroupMessagesScreen.propTypes = {
	/**
	 * Id of group to display
	 * {Number}
	 */
	groupId: PropTypes.number,
	/**
	 * If the group is not yet available in the app state, the component will attempt to load a list of groups.
	 * You can use this field to search for the specific group you want to load instead of loading a list of groups.
	 * {String}
	 */
	searchTerm: PropTypes.string,
	/**
	 * Use `true` to hide the back button
	 * {Boolean}
	 */
	hideBackButton: PropTypes.bool,
	/**
	 * Use `true` to hide cancel button when creating a new message
	 * {Boolean}
	 */
	hideCancelButton: PropTypes.bool,
	/**
	 * Use `true` to hide the screen title container
	 * {Boolean}
	 */
	hideNavigationHeader: PropTypes.bool,
	/**
	 * List screen title
	 * {String}
	 */
	screenTitle: PropTypes.string,
	/**
	 * Use `private` to send a message using the Send Individual Messages option. Otherwise, this will use the "Create New Thread" option
	 * {Boolean}
	 */
	screenType: PropTypes.string,
	/**
	 * Use `false` to hide search box
	 * {Boolean}
	 */
	showSearch: PropTypes.bool,
	/**
	 * Use this to display your own loading component while the screen is loading
	 * {ReactComponent}
	 */
	LoadingComponent: PropTypes.elementType
};