> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/screen/close.md).

# 关闭屏幕

***

### 1. 关闭页面（`closeView`)

这是一个关闭当前页面的函数。可以在按下“关闭”按钮并结束服务时使用。

**签名**

```typescript
function closeView(): Promise<void>;
```

**示例**

```tsx
import { Button } from 'react-native';
import { closeView } from '@granite-js/react-native';

function CloseButton() {
  return <Button title="关闭" onPress={closeView} />;
}
```

***

### 2. 设置 iOS 滑动返回（`setIosSwipeGestureEnabled`)

在 iOS 上启用或禁用通过滑动屏幕返回的手势。

**签名**

```typescript
function setIosSwipeGestureEnabled(options: { isEnabled: boolean }): Promise<void>;
```

**参数**

* **options.isEnabled** · 必填 · `boolean`

  `true`时，可以通过滑动返回， `false`时，滑动返回会被禁用。

**示例**

```tsx
import { setIosSwipeGestureEnabled } from '@apps-in-toss/framework';
import { Button } from 'react-native';

function Page() {
  return (
    <>
      <Button title="关闭滑动" onPress={() => setIosSwipeGestureEnabled({ isEnabled: false })} />
      <Button title="开启滑动" onPress={() => setIosSwipeGestureEnabled({ isEnabled: true })} />
    </>
  );
}
```

***

### 3. 控制返回事件（`useBackEvent`)

这是一个可以注册和移除返回事件的 Hook。只有在特定组件处于激活状态时，才能处理返回事件。

**签名**

```typescript
function useBackEvent(): BackEventControls;
```

**返回值**

* BackEventControls

  这是一个控制返回事件的对象。 `addEventListener`用于注册事件， `removeEventListener`用于移除。

{% hint style="info" %}
**请注意**

这个 Hook 必须 `BackEventProvider` 在其中使用。否则会发生错误。
{% endhint %}

**示例**

```tsx
import { useEffect, useState } from 'react';
import { Alert, Button, View } from 'react-native';
import { useBackEvent } from '@granite-js/react-native';

function UseBackEventExample() {
  const backEvent = useBackEvent();
  const [handler, setHandler] = useState<{ callback: () => void } | undefined>(undefined);

  useEffect(() => {
    const callback = handler?.callback;
    if (callback != null) {
      backEvent.addEventListener(callback);
      return () => {
        backEvent.removeEventListener(callback);
      };
    }
  }, [backEvent, handler]);

  return (
    <View>
      <Button title="注册返回事件" onPress={() => setHandler({ callback: () => Alert.alert('back') })} />
      <Button title="移除返回事件" onPress={() => setHandler(undefined)} />
    </View>
  );
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/screen/close.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
