Source

containers/Custom/GroupsScreen.tsx

// @flow
import {mapProps, compose} from "recompose";
import React from "react";
import IconButton from "../../components/IconButton";
import {NavigationActions} from "react-navigation";
import GroupsFilter from "../../components/Groups/GroupsFilter";
import AuthWrapper from "../../components/AuthWrapper";
import {memberHasPermission, Permissions} from "../../reducers/permissions";
import {connect} from "react-redux";
import PropTypes from "prop-types";
import withActiveCallBacks from "../../navigators/react-navigation-addons/withActiveCallBacks";
import {withNavigation} from "react-navigation";

const screenTitle = "groups:headerTitle";

const buildFilterProps = props => ({
	navigation: props.navigation,
	screenTitle: screenTitle,
	showSearch: true,
	headerProps: {
		headerRight: props.canCreateGroup !== false && (
			<AuthWrapper>
				<IconButton
					icon={{fontIconName: "plus", weight: 200}} //plus,round-filled
					// icon={require("../../assets/img/plus-circle.png")} //plus,round-filled
					pressHandler={() => {
						props.navigation.dispatch(
							NavigationActions.navigate({
								routeName: "GroupManageDetails",
								params: {create: true}
							})
						);
					}}
					tintColor={props.screenProps.colors.headerIconColor}
					style={{
						height: 24
					}}
					rtlStyleFix="handled"
					withUnderlay={false}
					renderText={null}
					TouchableComponent={null}
					hitSlop={null}
					underlayColor="#000"
				/>
			</AuthWrapper>
		)
	},
	...props
});

const mapPropsHoc = mapProps(buildFilterProps);

/**
 * You can use this component to display your Groups screen in your custom screen.
 * @component
 * @example <caption> Create new screen with groups list and button that redirects to featured group </caption>
 * //In custom_code/components/MyCustomScreen.js...
 *
 * import React from 'react';
 * import { View, Button } from 'react-native';
 * import { useSelector } from "react-redux";
 * import { NavigationActions } from "react-navigation";
 * import GroupsScreen from "@src/containers/Custom/GroupsScreen";
 *
 * const MyCustomScreen = (props) => {
 *
 *    const groupId = 8;
 *    const state = useSelector((state) => state);
 *
 *    const goToFeaturedGroup = () => {
 *
 *      const group = state.groupsCache.byId.get(groupId ? groupId.toString() : "");
 *
 *      //Navigate to featured group
 *      props.navigation.dispatch(
 *        NavigationActions.navigate({
 *          routeName: "GroupsSingleScreen",
 *          params: {
 *            group: group
 *          },
 *          key: `GroupsSingleScreen-${group.id.toString()}`
 *        })
 *      )
 *   }
 *
 *  return (
 *    <View style={{ flex: 1 }}>
 *
 *      <View style={{flex: 0.8}}>
 *        <GroupsScreen {...props} showSearch={false} screenTitle="My Groups" hideFilters={true} hideTitle={false} hideNavigationHeader={true} />
 *      </View>
 *
 *      <View style={{ flex: 0.2, backgroundColor: props.screenProps.colors.bodyFrontBg }}>
 *         <Button title="Go to featured group" onPress={() => goToFeaturedGroup()} />
 *      </View>
 *
 *    </View>)
 * }
 *
 * MyCustomScreen.navigationOptions = {
 *  header: null
 * }
 *
 * 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 GroupsScreen = compose(
	connect(state => ({
		canCreateGroup: memberHasPermission(state)(Permissions.canCreateGroup)
	})),
	mapPropsHoc,
	withNavigation,
	withActiveCallBacks
)(GroupsFilter);

GroupsScreen.propTypes = {
	/**
	 * Define header height
	 * {Number}
	 */
	headerHeight: PropTypes.number,
	/**
	 * Use `true` to hide filters in the screen
	 * {Boolean}
	 */
	hideFilters: PropTypes.bool,
	/**
	 * Use `true` to hide the screen title container when scrolling
	 * {Boolean}
	 */
	hideNavigationHeader: PropTypes.bool,
	/**
	 * Use `true` to hide title of the screen
	 * {Boolean}
	 */
	hideTitle: PropTypes.bool,
	/**
	 * List screen title. Default comes from translation files in BuddyBoss site
	 * {String}
	 */
	screenTitle: PropTypes.string,
	/**
	 * Adjust the duration of the Search animation.
	 * A higher value means a longer duration of the animation.
	 * {Number}
	 */
	searchFocusedAnimationDuration: PropTypes.number,
	/**
	 * Amount of space which the header moves up when Search input is focused.
	 * A greater value means that the header will move higher.
	 * {Number}
	 */
	searchFocusedListTopSpace: PropTypes.number,
	/**
	 * Use `false` to hide search box
	 * {Boolean}
	 */
	showSearch: PropTypes.bool
};

export default GroupsScreen;