Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 19.3.0
Inline banners on Android and iOS can push the app down instead of covering it, like on the web. Wrap the app in `GleapBannerArea` (for example `MaterialApp(builder: (context, child) => GleapBannerArea(child: child!))`): while an inline banner is shown, the app moves down by the banner's height (animated) and its top safe-area padding shrinks by the same amount, since the banner covers the status bar. Floating banners still float above the app. `Gleap.bannerHeight` is a `ValueListenable<double>` with the current height in logical pixels for custom layouts.
Updated native iOS dependency to 19.3.0
Updated native Android dependency to 19.3.0

## 19.2.4
Android: the realtime socket opens and closes far less often (no reconnect on a network change or an unchanged identify, closed with 1001 after 10 s in the background, backoff reset only after a healthy socket); see the Android SDK 19.2.4 notes.
Updated native iOS dependency to 19.2.4
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ dependencies:
gleap_sdk: "^19.0.1"
```

**Inline banners**

Inline banners (the banner style set in the Gleap dashboard) cover the top of the app on Android and iOS. To push the app down below them instead, like inline banners on the web, wrap it in `GleapBannerArea`:

```dart
MaterialApp(
builder: (context, child) => GleapBannerArea(child: child!),
home: const HomeScreen(),
)
```

Floating banners still float above the app; `Gleap.bannerHeight` gives the height for custom layouts.

**Flutter v2 support**

If you are using Flutter < v3, please import the gleap_sdk as shown below:
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ android {
}

dependencies {
implementation 'io.gleap:gleap-android-sdk:19.2.4'
implementation 'io.gleap:gleap-android-sdk:19.3.0'
}
}
11 changes: 11 additions & 0 deletions android/src/main/java/io/gleap/gleap_sdk/GleapSdkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.gleap.callbacks.FeedbackSentCallback;
import io.gleap.callbacks.OutboundSentCallback;
import io.gleap.callbacks.GetBitmapCallback;
import io.gleap.callbacks.BannerHeightChangedCallback;
import io.gleap.callbacks.NotificationUnreadCountUpdatedCallback;
import io.gleap.callbacks.RegisterPushMessageGroupCallback;
import io.gleap.callbacks.UnRegisterPushMessageGroupCallback;
Expand Down Expand Up @@ -165,6 +166,13 @@ public void invoke(int count) {
channel.invokeMethod("notificationCountUpdated", count);
}
});

Gleap.getInstance().setBannerHeightChangedCallback(new BannerHeightChangedCallback() {
@Override
public void invoke(int height) {
uiThreadHandler.post(() -> channel.invokeMethod("bannerHeightChanged", height));
}
});
}

private void initialize() {
Expand Down Expand Up @@ -567,6 +575,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "isOpened":
result.success(Gleap.getInstance().isOpened());
break;
case "getBannerHeight":
result.success(Gleap.getInstance().getBannerHeight());
break;
case "log":
if(call.argument("logLevel") != null) {
GleapLogLevel logLevel = GleapLogLevel.INFO;
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Keeps the app below inline banners instead of under them.
builder: (context, child) => GleapBannerArea(child: child!),
home: const MainScreen(),
routes: {
MainScreen.routeName: (context) => const MainScreen(),
Expand Down
4 changes: 2 additions & 2 deletions ios/gleap_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
Pod::Spec.new do |s|
s.name = 'gleap_sdk'
s.version = '19.2.4'
s.version = '19.3.0'
s.summary = 'Gleap SDK for Flutter'
s.description = 'Gleap SDK for Flutter with customer support, live chat, bug reporting and feedback.'
s.homepage = 'https://www.gleap.ai'
Expand All @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.public_header_files = 'gleap_sdk/Sources/gleap_sdk/include/**/*.h'
s.dependency 'Flutter'
s.platform = :ios, '15.0'
s.dependency 'Gleap', '19.2.4'
s.dependency 'Gleap', '19.3.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down
2 changes: 1 addition & 1 deletion ios/gleap_sdk/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
// Generated by the Flutter tool next to the plugin's package (Flutter 3.41+).
.package(name: "FlutterFramework", path: "../FlutterFramework"),
// Native Gleap iOS SDK. Bumped together with pubspec.yaml on every release.
.package(url: "https://github.com/GleapSDK/Gleap-iOS-SDK.git", from: "19.2.4")
.package(url: "https://github.com/GleapSDK/Gleap-iOS-SDK.git", from: "19.3.0")
],
targets: [
.target(
Expand Down
11 changes: 11 additions & 0 deletions ios/gleap_sdk/Sources/gleap_sdk/GleapSdkPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ - (void)notificationCountUpdated:(int)count {
});
}

- (void)bannerHeightChanged:(CGFloat)height {
dispatch_async(dispatch_get_main_queue(), ^{
if (self.methodChannel != nil) {
[self.methodChannel invokeMethod:@"bannerHeightChanged"
arguments:@(height)];
}
});
}

- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
if ([@"initialize" isEqualToString:call.method]) {
Expand Down Expand Up @@ -423,6 +432,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
} else if ([@"setModalUrl" isEqualToString:call.method]) {
[Gleap setModalUrl:call.arguments[@"url"]];
result(nil);
} else if ([@"getBannerHeight" isEqualToString:call.method]) {
result(@([Gleap bannerHeight]));
} else if ([@"isOpened" isEqualToString:call.method]) {
BOOL isOpened = [Gleap isOpened];
result(@(isOpened));
Expand Down
35 changes: 35 additions & 0 deletions lib/gleap_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -14,6 +15,7 @@ import 'package:gleap_sdk/models/gleap_user_property_model/gleap_user_property_m
export 'package:gleap_sdk/models/gleap_network_log_models/gleap_network_log_model/gleap_network_log_model.dart';
export 'package:gleap_sdk/models/gleap_network_log_models/gleap_network_request_model/gleap_network_request_model.dart';
export 'package:gleap_sdk/models/gleap_network_log_models/gleap_network_response_model/gleap_network_response_model.dart';
export 'package:gleap_sdk/widgets/gleap_banner_area.dart';

enum Severity { LOW, MEDIUM, HIGH }

Expand Down Expand Up @@ -75,6 +77,20 @@ class Gleap {
canPush: _isSupportedPlatform,
);

static final ValueNotifier<double> _bannerHeight = ValueNotifier<double>(0);

/// ### bannerHeight
///
/// The space an inline banner takes at the top of the screen, in logical
/// pixels from the top edge (it covers the status bar). 0 while no inline
/// banner is shown; floating banners float above the app and stay at 0.
/// [GleapBannerArea] uses it to keep the app below the banner.
///
/// **Available Platforms**
///
/// Android, iOS
static ValueListenable<double> get bannerHeight => _bannerHeight;

static bool _isSupportedPlatform() {
return kIsWeb || io.Platform.isAndroid || io.Platform.isIOS;
}
Expand Down Expand Up @@ -135,6 +151,11 @@ class Gleap {
return null;
}

if (call.method == 'bannerHeightChanged') {
_setBannerHeight(call.arguments);
return null;
}

if (call.method == 'feedbackWillBeSentCallback') {
WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();
WidgetsBinding.instance.focusManager.rootScope.requestFocus(
Expand Down Expand Up @@ -199,6 +220,20 @@ class Gleap {
'initialize',
{'token': token},
);

if (!kIsWeb) {
// A banner may already be shown, for example after a hot restart or
// when the app gets a new Flutter engine: the native SDK only reports
// changes.
try {
_setBannerHeight(await _channel.invokeMethod('getBannerHeight'));
} catch (_) {}
}
}

static void _setBannerHeight(dynamic height) {
_bannerHeight.value =
height is num ? math.max(0.0, height.toDouble()) : 0.0;
}

/// ### startFeedbackFlow
Expand Down
77 changes: 77 additions & 0 deletions lib/widgets/gleap_banner_area.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';
import 'package:gleap_sdk/gleap_sdk.dart';

/// Keeps [child] below an inline Gleap banner, like inline banners on the web:
/// while one is shown at the top of the screen, [child] moves down by the
/// banner's height instead of being covered, and moves back up when it closes.
/// Floating banners still float above the app.
///
/// The banner covers the status bar, so the top safe-area padding [child]
/// sees in [MediaQuery] shrinks by the banner's height.
///
/// Wrap the whole app, for example in `MaterialApp.builder`:
///
/// ```dart
/// MaterialApp(
/// builder: (context, child) => GleapBannerArea(child: child!),
/// home: const HomeScreen(),
/// )
/// ```
///
/// Android and iOS; on the web the Gleap JavaScript SDK already pushes the page
/// down, so this does nothing there.
class GleapBannerArea extends StatelessWidget {
const GleapBannerArea({
super.key,
required this.child,
this.duration = const Duration(milliseconds: 250),
this.curve = Curves.easeOut,
});

final Widget child;

/// How long [child] takes to move when a banner opens, resizes or closes.
final Duration duration;

final Curve curve;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder<double>(
valueListenable: Gleap.bannerHeight,
builder: (BuildContext context, double bannerHeight, Widget? child) {
return TweenAnimationBuilder<double>(
tween: Tween<double>(end: bannerHeight),
duration: duration,
curve: curve,
child: child,
builder: (BuildContext context, double top, Widget? child) {
final MediaQueryData? mediaQuery = MediaQuery.maybeOf(context);
Widget content = child!;
if (mediaQuery != null) {
content = MediaQuery(
data: mediaQuery.copyWith(
padding: mediaQuery.padding.copyWith(
top: math.max(0.0, mediaQuery.padding.top - top),
),
viewPadding: mediaQuery.viewPadding.copyWith(
top: math.max(0.0, mediaQuery.viewPadding.top - top),
),
),
child: content,
);
}

return Padding(
padding: EdgeInsets.only(top: top),
child: content,
);
},
);
},
child: child,
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: gleap_sdk
description: "Gleap SDK for Flutter: customer support, live chat, in-app bug reporting and customer feedback."
version: 19.2.4
version: 19.3.0
homepage: https://www.gleap.ai

environment:
Expand Down
Loading