# Overriding Navigation Behaviour

Navigation logic in UIKit can be readily customized by subclassing the predefined `Behaviour` classes and overriding relevant events. UIKit effectively decouples navigation logic and events by distributing them into separate `Behaviour` classes for each page.

\
UIKit includes the `UIKitBehaviour` class, which encompasses all the behavior classes utilized by it. These classes are standard classes that expose navigation events and other events that can be overridden as permitted by UIKit.

### Overriding Behaviour Class

This example illustrates how to override the `Behaviour` class and configure a custom `Behaviour` class within the UIKit framework.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/e9f64f7bb274e461ebbf207a2af95449>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/85d5a80eb7feaf332bf1b0351c264f89>" %}
{% endtab %}
{% endtabs %}

### Advanced iOS Navigation:

Our **UIKit v4** framework leverages **SwiftUI** extensively to build pages, components, and elements. These SwiftUI pages are embedded within Apple’s `UINavigationController`, allowing seamless navigation between screens.

To integrate SwiftUI with UIKit, we provide two hosting controller classes:

* `AmitySwiftUIHostingController`
* `AmitySwiftUIHostingNavigationController`

These classes allow you to wrap SwiftUI views and present them from UIKit-based view controllers.

**Navigation Bar Customization**

This architecture also offers the flexibility to customize the **Navigation Bar** beyond what SwiftUI currently supports. To enable these customizations while retaining the native **interactive swipe-to-pop** gesture, we override gesture handling behavior at a global level on `UINavigationController`.

Specifically, we override the following methods:

* `gestureRecognizerShouldBegin(_:_)`
* `gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)`

This ensures that the swipe-to-go-back gesture remains functional even with customizations.

**Custom Gesture Behavior**

We also provide a class called `AmitySwipeToBackGestureBehavior`, which gives you control over the swipe-to-pop gesture behavior. You can subclass this and override its functionality as needed.

To apply your custom gesture behavior, assign an instance of your subclass to the `swipeToBackGestureBehavior` property when initializing your screen or controller within UIKit v4.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/dd3a184eebcca26c9a23841bd8f6dadd>" %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.social.plus/social-plus-uikit/uikit-4/customization/overriding-navigation-behaviour.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
