Skip to content

feat: Adapt to HarmonyOS NEXT #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2024
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
8 changes: 5 additions & 3 deletions DropdownAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ const DropdownAlert: React.FunctionComponent<DropdownAlertProps> = ({
const windowDimensions = useWindowDimensions();
const isIOS = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';
const isHarmony = Platform.OS === 'harmony';

const isBelowIOS11 = isIOS && Number(Platform.Version) < 11;
const [dimValue, setDimValue] = useState(0);
const [height, setHeight] = useState(99);
Expand Down Expand Up @@ -411,7 +413,7 @@ const DropdownAlert: React.FunctionComponent<DropdownAlertProps> = ({

function _updateStatusBar(active = false, type = '') {
if (updateStatusBar && alertPosition === DropdownAlertPosition.Top) {
if (isAndroid) {
if (isAndroid||isHarmony) {
if (active) {
let backgroundColor = activeStatusBarBackgroundColor;
if (!backgroundColor) {
Expand Down Expand Up @@ -607,11 +609,11 @@ const DropdownAlert: React.FunctionComponent<DropdownAlertProps> = ({
let additionalAlertViewStyle: ViewStyle = {
backgroundColor: _getBackgroundColorForType(alertData.type),
};
if (isAndroid && translucent) {
if ((isAndroid ||isHarmony) && translucent) {
additionalAlertViewStyle.marginTop = StatusBar.currentHeight;
}
let SafeView = SafeAreaView;
if (isBelowIOS11 || isAndroid) {
if (isBelowIOS11 || isAndroid || isHarmony) {
SafeView = View;
}
return (
Expand Down
90 changes: 10 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,19 @@
# react-native-dropdownalert
# @react-native-oh-tpl/react-native-dropdownalert

[![Platform](https://img.shields.io/badge/-react--native-grey.svg?style=for-the-badge&logo=react)](https://reactnative.dev)
[![npm version](https://img.shields.io/npm/v/react-native-dropdownalert.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/react-native-dropdownalert)
[![npm version](https://img.shields.io/npm/dm/react-native-dropdownalert.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/react-native-dropdownalert)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge)](https://raw.github.com/testshallpass/react-native-dropdownalert/master/LICENSE)
[![CI](https://github.com/testshallpass/react-native-dropdownalert/actions/workflows/ci.yml/badge.svg)](https://github.com/testshallpass/react-native-dropdownalert/actions/workflows/ci.yml)
本项目基于 [react-native-dropdownalert](https://github.com/testshallpass/react-native-dropdownalert)

![screenshot](./screenshots/demo.gif)
## 文档地址 / Documentation URL

## Table of contents
[中文 / Chinese](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-dropdownalert.md)

- [Installation](#installation)
- [Usage](#usage)
- [Support](#support)
- [Using children prop](#using-children-prop)
- [Caveats](#caveats)
- [More Examples](./example/App.tsx)
[英文 / English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-en/react-native-dropdownalert.md)

An alert to notify users about an error or something else. It can be dismissed by press, cancel, automatic, pan gesture or programmatic. It can be customized and/or you can build your own alert (BYOA) - see [DropdownAlertProps](./DropdownAlert.tsx) on what's available.
## Codegen

## Installation
该库已接入 codegen,具体请查阅文档。

- `yarn add react-native-dropdownalert`
- `npm i react-native-dropdownalert --save`
The library has been integrated with codegen. Please refer to the documentation for details.

## Usage
## 请悉知 / Acknowledgements

import the library

```javascript
import DropdownAlert, {
DropdownAlertData,
DropdownAlertType,
} from 'react-native-dropdownalert';
```

create an alert promise function variable

```javascript
let alert = (_data: DropdownAlertData) => new Promise<DropdownAlertData>(res => res);
```

add the component as the last component in the document tree so it overlaps other UI components and set alert prop with alert function

```javascript
<DropdownAlert alert={func => (alert = func)} />
```

invoke alert

```javascript
const alertData = await alert({
type: DropdownAlertType.Error,
title: 'Error',
message: 'Something went wrong.',
});
```

## Support

| react minium version | react-native minium version | package version | reason |
| :------------------: | :-------------------------: | :-------------: | ------------------- |
| v16.8.0 | v0.61.0 | v5.0.0 | use react hooks |
| v16.0.0 | v0.50.0 | v3.2.0 | use `SafeAreaView` |
| v16.0.0-alpha.6 | v0.44.0 | v2.12.0 | use `ViewPropTypes` |

## Using `children` prop

Option 1 pass child component(s) like so:

```javascript
<DropdownAlert>{/* insert child component(s) */}</DropdownAlert>
```

Option 2 pass child component(s) like so:

```javascript
<DropdownAlert children={/* insert child component(s) */} />
```

Either way `DropdownAlert` will render these instead of the pre-defined child components when alert is invoked. Check out the iOS and Android notifications in example project.

## Caveats

- Modals can overlap `DropdownAlert`` if it is not inside the modal's document tree.
- It is important you place the `DropdownAlert` below the `StackNavigator`.

> Inspired by: [RKDropdownAlert](https://github.com/cwRichardKim/RKDropdownAlert)
本项目基于 [MIT License (MIT)](https://github.com/testshallpass/react-native-dropdownalert/blob/main/LICENSE) ,请自由地享受和参与开源。
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-native-dropdownalert",
"name": "@react-native-oh-tpl/react-native-dropdownalert",
"version": "5.1.0",
"description": "An alert to notify users about an error or something else.",
"main": "DropdownAlert.tsx",
Expand All @@ -11,12 +11,13 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/testshallpass/react-native-dropdownalert.git"
"url": "git://github.com/react-native-oh-library/react-native-dropdownalert.git"
},
"keywords": [
"react-native",
"ios",
"android",
"harmony"
"dropdown",
"alert",
"dismiss",
Expand Down Expand Up @@ -51,5 +52,8 @@
"ts-jest": "29.1.1",
"ts-node": "10.9.2",
"typescript": "5.0.4"
},
"harmony": {
"alias": "react-native-dropdownalert"
}
}