Skip to content
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
27 changes: 21 additions & 6 deletions ios/OrientationDirector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#import "OrientationDirector/OrientationDirector-Swift.h"
#endif

#include <exception>

static OrientationDirectorImpl *_director = SharedOrientationDirectorImpl.shared;

///////////////////////////////////////////////////////////////////////////////////////
/// EVENT EMITTER SETUP
///https://github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/swift-event-emitter
@interface OrientationDirector() <OrientationEventEmitterDelegate>
@end
///
Expand Down Expand Up @@ -43,17 +44,31 @@ + (BOOL)requiresMainQueueSetup
///////////////////////////////////////////////////////////////////////////////////////
/// EVENT EMITTER SETUP
///
-(void)emitOnDeviceOrientationDidChangeWithParams:(NSDictionary*)params {
[self emitOnDeviceOrientationChanged:params];

-(void)emitDeviceOrientationChangedWithParams:(NSDictionary*)params {
try {
[self emitOnDeviceOrientationChanged:params];
} catch (std::exception &e) {
// Ignore if no listeners
}
}

-(void)emitOnInterfaceOrientationDidChangeWithParams:(NSDictionary*)params {
[self emitOnInterfaceOrientationChanged:params];
-(void)emitInterfaceOrientationChangedWithParams:(NSDictionary*)params {
try {
[self emitOnInterfaceOrientationChanged:params];
} catch (std::exception &e) {
// Ignore if no listeners
}
}

-(void)emitOnLockChangedWithParams:(NSDictionary*)params {
[self emitOnLockChanged:params];
try {
[self emitOnLockChanged:params];
} catch (std::exception &e) {
// Ignore if no listeners
}
}

///
///////////////////////////////////////////////////////////////////////////////////////

Expand Down
10 changes: 5 additions & 5 deletions ios/implementation/EventManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class EventManager: NSObject {
guard let delegate = delegate else {
return
}

let params = Dictionary(dictionaryLiteral: ("orientation", value))
delegate.emitOnDeviceOrientationDidChange(params: params as NSDictionary)
delegate.emitDeviceOrientationChanged(params: params as NSDictionary)
}

func sendInterfaceOrientationDidChange(value: Int) {
Expand All @@ -25,7 +25,7 @@ public class EventManager: NSObject {
}

let params = Dictionary(dictionaryLiteral: ("orientation", value))
delegate.emitOnInterfaceOrientationDidChange(params: params as NSDictionary)
delegate.emitInterfaceOrientationChanged(params: params as NSDictionary)
}

func sendLockDidChange(value: Bool) {
Expand All @@ -40,6 +40,6 @@ public class EventManager: NSObject {

@objc public protocol OrientationEventEmitterDelegate {
func emitOnLockChanged(params: NSDictionary)
func emitOnDeviceOrientationDidChange(params: NSDictionary)
func emitOnInterfaceOrientationDidChange(params: NSDictionary)
func emitDeviceOrientationChanged(params: NSDictionary)
func emitInterfaceOrientationChanged(params: NSDictionary)
}
15 changes: 8 additions & 7 deletions src/EventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform, type EventSubscription } from 'react-native';
import Module from './module';
import { type EventSubscription, Platform } from 'react-native';
import NativeOrientationDirector from './NativeOrientationDirector';
import type { OrientationEvent } from './types/OrientationEvent.interface';
import type { LockedEvent } from './types/LockedEvent.interface';

Expand All @@ -9,15 +9,16 @@ class EventEmitter {
static addDeviceOrientationDidChangeListener(
callback: (orientation: OrientationEvent) => void
) {
let listener = Module.onDeviceOrientationChanged(callback);
let listener =
NativeOrientationDirector.onDeviceOrientationChanged(callback);

if (Platform.OS !== 'android') {
return listener;
}

EventEmitter.androidListenerCount++;
if (EventEmitter.androidListenerCount === 1) {
Module.enableOrientationSensors();
NativeOrientationDirector.enableOrientationSensors();
}

return EventEmitter.createDeviceOrientationListenerProxy(listener);
Expand All @@ -26,11 +27,11 @@ class EventEmitter {
static addInterfaceOrientationDidChangeListener(
callback: (orientation: OrientationEvent) => void
) {
return Module.onInterfaceOrientationChanged(callback);
return NativeOrientationDirector.onInterfaceOrientationChanged(callback);
}

static addLockDidChangeListener(callback: (event: LockedEvent) => void) {
return Module.onLockChanged(callback);
return NativeOrientationDirector.onLockChanged(callback);
}

private static createDeviceOrientationListenerProxy(
Expand All @@ -50,7 +51,7 @@ class EventEmitter {
function disableOrientationSensorsIfLastListener() {
if (EventEmitter.androidListenerCount === 1) {
EventEmitter.androidListenerCount = 0;
Module.disableOrientationSensors();
NativeOrientationDirector.disableOrientationSensors();
return;
}

Expand Down
22 changes: 11 additions & 11 deletions src/RNOrientationDirector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform } from 'react-native';
import Module from './module';
import NativeOrientationDirector from './NativeOrientationDirector';
import type { HumanReadableOrientationsResource } from './types/HumanReadableOrientationsResource.type';
import { Orientation } from './types/Orientation.enum';
import { AutoRotation } from './types/AutoRotation.enum';
Expand Down Expand Up @@ -39,11 +39,11 @@ class RNOrientationDirector {
}

static getInterfaceOrientation(): Promise<Orientation> {
return Module.getInterfaceOrientation();
return NativeOrientationDirector.getInterfaceOrientation();
}

static getDeviceOrientation(): Promise<Orientation> {
return Module.getDeviceOrientation();
return NativeOrientationDirector.getDeviceOrientation();
}

/**
Expand All @@ -69,42 +69,42 @@ class RNOrientationDirector {
orientationType: OrientationType = OrientationType.interface
) {
if (orientationType === OrientationType.interface) {
Module.lockTo(orientation);
NativeOrientationDirector.lockTo(orientation);
return;
}

if (orientation === Orientation.landscapeLeft) {
Module.lockTo(Orientation.landscapeRight);
NativeOrientationDirector.lockTo(Orientation.landscapeRight);
return;
}

if (orientation === Orientation.landscapeRight) {
Module.lockTo(Orientation.landscapeLeft);
NativeOrientationDirector.lockTo(Orientation.landscapeLeft);
return;
}

Module.lockTo(orientation);
NativeOrientationDirector.lockTo(orientation);
}

static unlock() {
Module.unlock();
NativeOrientationDirector.unlock();
}

static isLocked() {
return Module.isLocked();
return NativeOrientationDirector.isLocked();
}

static isAutoRotationEnabled() {
if (Platform.OS !== 'android') {
return AutoRotation.unknown;
}
return Module.isAutoRotationEnabled()
return NativeOrientationDirector.isAutoRotationEnabled()
? AutoRotation.enabled
: AutoRotation.disabled;
}

static resetSupportedInterfaceOrientations() {
Module.resetSupportedInterfaceOrientations();
NativeOrientationDirector.resetSupportedInterfaceOrientations();
}

static listenForDeviceOrientationChanges(
Expand Down
28 changes: 0 additions & 28 deletions src/module.ts

This file was deleted.