react-native-toast-message 2.2.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RNSafeAreaModule : NSObject <RCTBridgeModule>
4
+
5
+ @end
@@ -0,0 +1,27 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
3
+ @interface SafeAreaModule : NSObject <RCTBridgeModule>
4
+ @end
5
+
6
+ @implementation SafeAreaModule
7
+ RCT_EXPORT_MODULE();
8
+
9
+ RCT_EXPORT_METHOD(getSafeAreaInsets:(RCTResponseSenderBlock)callback) {
10
+ UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
11
+ UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero;
12
+
13
+ if (@available(iOS 11.0, *)) {
14
+ safeAreaInsets = rootViewController.view.safeAreaInsets;
15
+ }
16
+
17
+ NSDictionary *result = @{
18
+ @"top": @(safeAreaInsets.top),
19
+ @"bottom": @(safeAreaInsets.bottom),
20
+ @"left": @(safeAreaInsets.left),
21
+ @"right": @(safeAreaInsets.right)
22
+ };
23
+
24
+ callback(@[[NSNull null], result]);
25
+ }
26
+
27
+ @end
@@ -3,3 +3,4 @@ export * from './useSlideAnimation';
3
3
  export * from './useTimeout';
4
4
  export * from './usePanResponder';
5
5
  export * from './useKeyboard';
6
+ export * from './useSafeArea';
@@ -3,3 +3,4 @@ export * from './useSlideAnimation';
3
3
  export * from './useTimeout';
4
4
  export * from './usePanResponder';
5
5
  export * from './useKeyboard';
6
+ export * from './useSafeArea';
@@ -0,0 +1,10 @@
1
+ declare type TSafeArea = {
2
+ top: number;
3
+ bottom: number;
4
+ left: number;
5
+ right: number;
6
+ };
7
+ export declare const useSafeArea: () => {
8
+ safeAreaInsets: TSafeArea | null;
9
+ };
10
+ export {};
@@ -0,0 +1,25 @@
1
+ import { NativeModules, StatusBar } from 'react-native';
2
+ import { useEffect, useState } from "react";
3
+ import { isIOS } from "../utils/platform";
4
+ import { SCREEN_HEIGHT, WINDOW_HEIGHT } from "../utils/dimension";
5
+ export const useSafeArea = () => {
6
+ const [safeAreaInsets, setSafeAreaInsets] = useState(null);
7
+ useEffect(() => {
8
+ if (isIOS()) {
9
+ NativeModules?.SafeAreaModule?.getSafeAreaInsets((error, result) => {
10
+ if (error) {
11
+ console.error(error);
12
+ }
13
+ else {
14
+ setSafeAreaInsets(result);
15
+ }
16
+ });
17
+ }
18
+ else {
19
+ const statusBarHeight = StatusBar.currentHeight ?? 0;
20
+ const bottomInset = SCREEN_HEIGHT - WINDOW_HEIGHT - statusBarHeight;
21
+ setSafeAreaInsets({ top: statusBarHeight, bottom: bottomInset, left: 0, right: 0 });
22
+ }
23
+ }, []);
24
+ return { safeAreaInsets };
25
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { useLogger } from './contexts';
3
- import { useTimeout } from './hooks';
3
+ import { useSafeArea, useTimeout } from './hooks';
4
4
  import { noop } from './utils/func';
5
5
  import { mergeIfDefined } from './utils/obj';
6
6
  export const DEFAULT_DATA = {
@@ -27,6 +27,7 @@ export function useToast({ defaultOptions }) {
27
27
  const { log } = useLogger();
28
28
  const [isVisible, setIsVisible] = React.useState(false);
29
29
  const [data, setData] = React.useState(DEFAULT_DATA);
30
+ const { safeAreaInsets } = useSafeArea();
30
31
  const initialOptions = mergeIfDefined(DEFAULT_OPTIONS, defaultOptions);
31
32
  const [options, setOptions] = React.useState(initialOptions);
32
33
  const onAutoHide = React.useCallback(() => {
@@ -43,7 +44,9 @@ export function useToast({ defaultOptions }) {
43
44
  }, [clearTimer, log, options]);
44
45
  const show = React.useCallback((params) => {
45
46
  log(`Showing with params: ${JSON.stringify(params)}`);
46
- const { text1 = DEFAULT_DATA.text1, text2 = DEFAULT_DATA.text2, type = initialOptions.type, text1Style = initialOptions.text1Style, text2Style = initialOptions.text2Style, position = initialOptions.position, autoHide = initialOptions.autoHide, visibilityTime = initialOptions.visibilityTime, topOffset = initialOptions.topOffset, bottomOffset = initialOptions.bottomOffset, keyboardOffset = initialOptions.keyboardOffset, onShow = initialOptions.onShow, onHide = initialOptions.onHide, onPress = initialOptions.onPress, swipeable = initialOptions.swipeable, props = initialOptions.props } = params;
47
+ const topOffset = safeAreaInsets && safeAreaInsets.top > 0 ? safeAreaInsets.top : initialOptions.topOffset;
48
+ const bottomOffset = safeAreaInsets && safeAreaInsets.bottom > 0 ? safeAreaInsets.bottom : initialOptions.bottomOffset;
49
+ const { text1 = DEFAULT_DATA.text1, text2 = DEFAULT_DATA.text2, type = initialOptions.type, text1Style = initialOptions.text1Style, text2Style = initialOptions.text2Style, position = initialOptions.position, autoHide = initialOptions.autoHide, visibilityTime = initialOptions.visibilityTime, keyboardOffset = initialOptions.keyboardOffset, onShow = initialOptions.onShow, onHide = initialOptions.onHide, onPress = initialOptions.onPress, swipeable = initialOptions.swipeable, props = initialOptions.props } = params;
47
50
  setData({
48
51
  text1,
49
52
  text2
@@ -0,0 +1,2 @@
1
+ export declare const WINDOW_HEIGHT: number;
2
+ export declare const SCREEN_HEIGHT: number;
@@ -0,0 +1,3 @@
1
+ import { Dimensions } from "react-native";
2
+ export const { height: WINDOW_HEIGHT } = Dimensions.get('window');
3
+ export const { height: SCREEN_HEIGHT } = Dimensions.get('screen');
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "react-native-toast-message",
3
- "version": "2.2.0",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "Toast message component for React Native",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "files": [
8
- "/lib"
8
+ "/lib",
9
+ "ios",
10
+ "*.podspec"
9
11
  ],
10
12
  "repository": {
11
13
  "type": "git",
@@ -0,0 +1,41 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-toast-message"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = "https://github.com/calintamas/react-native-toast-message"
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "9.0" }
15
+ s.source = { :git => "https://github.com/calintamas/react-native-toast-message.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+
19
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21
+ if respond_to?(:install_modules_dependencies, true)
22
+ install_modules_dependencies(s)
23
+ else
24
+ s.dependency "React-Core"
25
+
26
+ # Don't install the dependencies when we run `pod install` in the old architecture.
27
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
28
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
29
+ s.pod_target_xcconfig = {
30
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
31
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
32
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
33
+ }
34
+ s.dependency "React-Codegen"
35
+ s.dependency "RCT-Folly"
36
+ s.dependency "RCTRequired"
37
+ s.dependency "RCTTypeSafety"
38
+ s.dependency "ReactCommon/turbomodule/core"
39
+ end
40
+ end
41
+ end