-
Notifications
You must be signed in to change notification settings - Fork 278
feat: add a ios native module to calculate inset top and bottom #511
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
Open
seyedmostafahasani
wants to merge
11
commits into
calintamas:main
Choose a base branch
from
seyedmostafahasani:chore/safe-area
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−7
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0bce335
chore: add safeArea for handling inset top and bottom
seyedmostafahasani 29b3d26
chore: update dependency
seyedmostafahasani 4d8a1db
chore: update package.json
seyedmostafahasani 394480b
feat: native module ios to calculate safeArea insets
seyedmostafahasani 757d63f
chore: update package.json
seyedmostafahasani 4ff5bb1
fix: unit tset
seyedmostafahasani 02b3801
chore: update instruction for installation
seyedmostafahasani 83aae7f
chore: update type location
seyedmostafahasani d812971
chore: yarn prettier
seyedmostafahasani 4edf05b
chore: yarn prettier
seyedmostafahasani de3ad8a
Update quick-start.md for expo project
seyedmostafahasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RNSafeAreaModule : NSObject <RCTBridgeModule> | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
@interface SafeAreaModule : NSObject <RCTBridgeModule> | ||
@end | ||
|
||
@implementation SafeAreaModule | ||
RCT_EXPORT_MODULE(); | ||
|
||
RCT_EXPORT_METHOD(getSafeAreaInsets:(RCTResponseSenderBlock)callback) { | ||
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; | ||
UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero; | ||
|
||
if (@available(iOS 11.0, *)) { | ||
safeAreaInsets = rootViewController.view.safeAreaInsets; | ||
} | ||
|
||
NSDictionary *result = @{ | ||
@"top": @(safeAreaInsets.top), | ||
@"bottom": @(safeAreaInsets.bottom), | ||
@"left": @(safeAreaInsets.left), | ||
@"right": @(safeAreaInsets.right) | ||
}; | ||
|
||
callback(@[[NSNull null], result]); | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "json" | ||
|
||
package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "react-native-toast-message" | ||
s.version = package["version"] | ||
s.summary = package["description"] | ||
s.homepage = "https://github.com/calintamas/react-native-toast-message" | ||
s.license = package["license"] | ||
s.authors = package["author"] | ||
|
||
s.platforms = { :ios => "9.0" } | ||
s.source = { :git => "https://github.com/calintamas/react-native-toast-message.git", :tag => "#{s.version}" } | ||
|
||
s.source_files = "ios/**/*.{h,m,mm,swift}" | ||
|
||
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. | ||
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. | ||
if respond_to?(:install_modules_dependencies, true) | ||
install_modules_dependencies(s) | ||
else | ||
s.dependency "React-Core" | ||
|
||
# Don't install the dependencies when we run `pod install` in the old architecture. | ||
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then | ||
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" | ||
s.pod_target_xcconfig = { | ||
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", | ||
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", | ||
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17" | ||
} | ||
s.dependency "React-Codegen" | ||
s.dependency "RCT-Folly" | ||
s.dependency "RCTRequired" | ||
s.dependency "RCTTypeSafety" | ||
s.dependency "ReactCommon/turbomodule/core" | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {NativeModules, StatusBar} from 'react-native' | ||
import {useEffect, useState} from "react"; | ||
import {isIOS} from "../utils/platform"; | ||
import {SCREEN_HEIGHT, WINDOW_HEIGHT} from "../utils/dimension"; | ||
|
||
type TSafeArea = { | ||
top: number | ||
bottom: number | ||
left: number | ||
right: number | ||
} | ||
|
||
type TNativeModulesSafeArea = { | ||
SafeAreaInsetsModule: { | ||
getSafeAreaInsets(p: (error: Error, result: TSafeArea) => void): Promise<{ | ||
top: number; | ||
bottom: number; | ||
left: number; | ||
right: number | ||
}>; | ||
}; | ||
} | ||
export const useSafeArea = () => { | ||
const [safeAreaInsets, setSafeAreaInsets] = useState<TSafeArea | null>(null); | ||
useEffect(() => { | ||
if (isIOS()) { | ||
NativeModules?.SafeAreaModule?.getSafeAreaInsets((error: Error, result: TSafeArea) => { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
setSafeAreaInsets(result) | ||
} | ||
}); | ||
} else { | ||
const statusBarHeight = StatusBar.currentHeight ?? 0 | ||
const bottomInset = SCREEN_HEIGHT - WINDOW_HEIGHT - statusBarHeight; | ||
setSafeAreaInsets({top: statusBarHeight, bottom: bottomInset, left: 0, right: 0}) | ||
} | ||
}, []) | ||
|
||
return {safeAreaInsets} | ||
} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {Dimensions} from "react-native"; | ||
|
||
export const {height: WINDOW_HEIGHT} = Dimensions.get('window') | ||
export const {height: SCREEN_HEIGHT} = Dimensions.get('screen') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.