Skip to content

Commit

Permalink
Add support for lockAllOrientationsButUpsideDown (wonday#110)
Browse files Browse the repository at this point in the history
* Add support for lockAllOrientationsButUpsideDown

* Add .ts docs

* Fix typo

* Fix mask
  • Loading branch information
andrei-tofan authored and wonday committed Jan 6, 2020
1 parent be05d90 commit bacc509
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ It can return either `PORTRAIT` `LANDSCAPE-LEFT` `LANDSCAPE-RIGHT` `UNKNOWN`
- `lockToLandscapeLeft()` this will lock to camera left home button right
- `lockToLandscapeRight()` this will lock to camera right home button left
- `lockToPortraitUpsideDown` only support android
- `lockToAllOrientationsButUpsideDown` only ios
- `unlockAllOrientations()`
- `getOrientation(function(orientation))`
- `getDeviceOrientation(function(deviceOrientation))`
Expand Down
12 changes: 12 additions & 0 deletions iOS/RCTOrientation/Orientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ - (void)lockToOrientation:(UIInterfaceOrientation) newOrientation usingMask:(UII
#endif
}

RCT_EXPORT_METHOD(lockToAllOrientationsButUpsideDown)
{
#if DEBUG
NSLog(@"Locking to all except upside down");
#endif
#if (!TARGET_OS_TV)
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[self lockToOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskAllButUpsideDown];
}];
#endif
}

RCT_EXPORT_METHOD(unlockAllOrientations)
{
#if DEBUG
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare class Orientation {
static lockToPortrait(): void;
static lockToLandscape(): void;
static lockToLandscapeLeft(): void;
static lockToAllOrientationsButUpsideDown(): void;
static lockToLandscapeRight(): void;
static lockToPortraitUpsideDown(): void;
static unlockAllOrientations(): void;
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ export default class Orientation {
OrientationNative.lockToLandscapeLeft();
};

// OrientationMaskAllButUpsideDown
static lockToAllOrientationsButUpsideDown = () => {
locked = true;
if (Platform.OS === "ios") {
OrientationNative.lockToAllOrientationsButUpsideDown();
}
};

static unlockAllOrientations = () => {
locked = false;
OrientationNative.unlockAllOrientations();
Expand Down

0 comments on commit bacc509

Please sign in to comment.