Display the community
Show the Octopus community screens inside your app, full screen or embedded in one of your screens.
Before you begin
- Initialize the SDK: see Initialize the SDK.
- If your users sign in with your own account system, link them first: see Link your user to the SDK.
How it works
The community UI starts on the main feed and handles its own navigation between feeds, posts, groups and profiles. You choose where it lives:
| Presentation | Android | iOS | Flutter | React Native | Unity |
|---|---|---|---|---|---|
| Full screen, over your app | Your own route | .fullScreenCover | showOctopusHomeScreen | openUI() | Open() |
| Embedded in one of your screens | OctopusHomeContent | OctopusHomeScreen in a tab | OctopusHomeScreen widget | <OctopusUIView> | Not available |
Your app gets callbacks when the community needs something only your app can do: sign the user in, edit a profile field your app owns, open a link, or show your own profile screen.
Show the community
- Android
- iOS
- Flutter
- React Native
- Unity
Add the OctopusHomeContent composable to your community screen:
navController: your mainNavHostController.onNavigateToLogin: called when the SDK needs a signed-in user. Start your login flow, then callOctopusSDK.connectUser(...).onNavigateToProfileEdit: called when the user taps a profile field your app owns.fieldToEdittells you which one, ornull. Open your profile editor, then callOctopusSDK.connectUser(...)again with the updated profile.
OctopusTheme {
OctopusHomeContent(
modifier = Modifier.fillMaxSize(),
navController = navController,
onNavigateToLogin = {
navController.navigate(LoginRoute)
},
onNavigateToProfileEdit = { fieldToEdit ->
navController.navigate(
ProfileRoute(focusNickname = fieldToEdit == ProfileField.NICKNAME),
)
},
)
}
Then register the other community screens in your main NavHost with octopusComposables. It adds one composable() destination per community screen to your NavGraphBuilder:
NavHost(navController = navController, startDestination = HomeRoute) {
// Your own destinations
octopusComposables(
navController = navController,
onNavigateToLogin = { navController.navigate(LoginRoute) },
onNavigateToProfileEdit = { fieldToEdit -> /* same as above */ },
) { backStackEntry, content ->
// Theme a community screen, possibly based on backStackEntry
OctopusTheme {
content()
}
}
}
When OctopusHomeContent, or the NavHost that holds octopusComposables, sits inside your own Scaffold, pass the innerPadding and consume it: Modifier.padding(innerPadding).consumeWindowInsets(innerPadding). Otherwise the system bar and keyboard insets count twice: the comment composer floats above the keyboard by the height of your bottom bar, and a gap shows under it when the keyboard is closed. This is the Compose guidance for nested Scaffolds.
See the samples for each integration: Community screen, Full screen, Bottom navigation bar, Floating bottom navigation bar and Single activity.
Import OctopusUI and show OctopusHomeScreen. The community handles its own navigation: do not put it inside your own NavigationStack.
navigationMode≥ 1.12.2: pass.navigationStackwhen you present the screen in a modal (.sheet,.fullScreenCover). Keep the default.automaticin a tab or on an existing stack. In a modal without.navigationStack, the navigation to post details can be dropped.
import OctopusUI
struct CommunityButton: View {
let octopus: OctopusSDK
@State private var openOctopus = false
var body: some View {
Button("Open the community") {
openOctopus = true
}
.fullScreenCover(isPresented: $openOctopus) {
OctopusHomeScreen(octopus: octopus, navigationMode: .navigationStack)
}
}
}
In a UIHostingController inside a UITabBarController, the hosted view can stop above the tab bar and leave an empty band. Let it extend under the bar: set hostingController.edgesForExtendedLayout = .all and hostingController.extendedLayoutIncludesOpaqueBars = true. bottomSafeAreaInset cannot fix this, it only adds space.
Choose how the community appears:
octopus.showOctopusHomeScreen(context, …): pushes the community full screen on your navigator. The returnedFuturecompletes when the route pops.OctopusHomeScreen: a widget you embed in your own layout, with the SDK top bar.OctopusHomeContent: the same widget without the SDK top bar, when your ownAppBaralready titles the screen. The top bar is removed on Android only. On iOS it renders likeOctopusHomeScreen.
Callbacks, the same on the three entry points:
onNavigateToLogin: called when the SDK needs a signed-in user.onModifyUser: called when the user taps a profile field your app owns.fieldnames it, or isnull.onNavigateToUrl: decide who opens a link: see Intercept URL openings.onNavigateToProfile: show your own profile screen for a member: see Route profile taps.
// Full screen
await octopus.showOctopusHomeScreen(
context,
onNavigateToLogin: () {
// Start your login flow
},
onModifyUser: (String? field) {
// Open your profile editor, focused on field
},
);
// Embedded
OctopusHomeScreen(
onNavigateToLogin: () {
// Start your login flow
},
onModifyUser: (String? field) {
// Open your profile editor, focused on field
},
)
Call initialize() first. Then choose how the community appears:
openUI(): shows the community full screen.closeUI()dismisses it from your code.<OctopusUIView>: embeds the community in one of your screens.
import { closeUI, openUI, OctopusUIView } from '@octopus-community/react-native';
import { StyleSheet, View } from 'react-native';
// Full screen
await openUI();
await closeUI();
// Embedded
function CommunityScreen() {
return (
<View style={{ flex: 1 }}>
<OctopusUIView style={StyleSheet.absoluteFill} />
</View>
);
}
Unity opens the community full screen only: it cannot embed it in one of your screens. Open it from any button or event:
OctopusSDK.Open();
Modify the bottom safe area
Android availableiOS availableFlutter ≥ 1.12.0React Native availableUnity not available
Reserve extra space at the bottom of the community UI, for example under your own bottom bar, so the floating "Write a post" button and the comment composer stay visible.
- Android
- iOS
- Flutter
- React Native
- Unity
Use the contentPadding parameter of OctopusHomeContent:
OctopusHomeContent(
modifier = Modifier.fillMaxSize(),
navController = navController,
contentPadding = PaddingValues(bottom = 10.dp),
)
Use the bottomSafeAreaInset parameter of OctopusHomeScreen. It adds space on top of the safe area the system already reserves:
- In a standard
TabVieworUITabBarControllertab, the system already keeps the content clear of the tab bar. Pass a few points of margin at most: passing the tab bar height counts it twice. - Under a custom or floating bar that the system does not reserve space for, pass the height of the bar that overlaps the content. Do not add the system safe area again.
OctopusHomeScreen(
octopus: octopus,
bottomSafeAreaInset: 10
)
See the embedded tab scenario of the iOS sample.
Use the bottomSafeAreaInset parameter of OctopusHomeScreen, in logical pixels. Pass the total bottom padding you want, typically the height of your own bottom bar. The system safe area is already applied.
OctopusHomeScreen(
onNavigateToLogin: () {},
bottomSafeAreaInset: 10,
)
≥ 1.13.0 Left at 0, the SDK reserves the bottom padding your layout still has, which clears the Android navigation bar or the iOS home indicator. To reserve nothing at all, remove that padding yourself:
MediaQuery.removePadding(
context: context,
removeBottom: true,
child: OctopusHomeScreen(onNavigateToLogin: () {}),
)
Pass ui.bottomSafeAreaInset to initialize(), in points on iOS and dp on Android:
import { initialize } from '@octopus-community/react-native';
await initialize({
apiKey: 'YOUR_API_KEY',
connectionMode: { type: 'sso', appManagedFields: [] },
ui: {
bottomSafeAreaInset: 10,
},
});
The value applies differently depending on the presentation:
- Full screen (
openUI()): extra space on top of the system safe area. Absent or0adds nothing. - Embedded (
<OctopusUIView>): the total bottom padding, the same on both platforms.0reserves nothing, for an edge-to-edge layout.
≥ 1.13.1 When the option is absent on an embedded view, Android reserves the part of the navigation bar that overlaps the view, and iOS adds 10 pt.
Modifying the bottom safe area is not yet available on Unity.