Skip to content
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"workspaces": [
"packages/*"
],
"version": "0.6.6",
"packageManager": "yarn@1.22.22",
"scripts": {
"lint": "eslint .",
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-external-display/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions packages/react-native-external-display/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
extends: [
'@fugood/eslint-config-react',
// 'plugin:ft-flow/recommended',
],
parser: 'hermes-eslint',
plugins: [
'ft-flow'
],
env: {
node: true,
browser: true,
jest: true,
},
rules: {
'import/order': 0,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.json', '.native.js', '.ios.js', '.android.js'],
},
},
},
}
3 changes: 3 additions & 0 deletions packages/react-native-external-display/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
60 changes: 60 additions & 0 deletions packages/react-native-external-display/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
7 changes: 7 additions & 0 deletions packages/react-native-external-display/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 80
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,126 @@
import java.util.Map;
import java.util.HashMap;

import android.util.Log;

import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
class ExternalDisplayScreen extends Presentation {
ExternalDisplayScreen(Context ctx, Display display) {
super(ctx, display);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
ExternalDisplayScreen(Context ctx, Display display) {
super(ctx, display);
Log.d("RNExternalDisplayEvent", "ExternalDisplayScreen init");

}

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("RNExternalDisplayEvent", "ExternalDisplayScreen onCreate");

super.onCreate(savedInstanceState);
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
class ExternalDisplayHelper implements DisplayManager.DisplayListener {
public static Map<String, Object> getScreenInfo(Display[] displays) {
HashMap<String, Object> info = new HashMap<String, Object>();
for (Display display : displays) {
int displayId = display.getDisplayId();
if (
display.getDisplayId() == Display.DEFAULT_DISPLAY ||
(display.getFlags() & Display.FLAG_PRESENTATION) == 0
) {
continue;
}
HashMap<String, Object> data = new HashMap<String, Object>();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
data.put("id", displayId);
data.put("width", displayMetrics.widthPixels);
data.put("height", displayMetrics.heightPixels);
info.put(String.valueOf(display.getDisplayId()), data);
private static final String TAG = "RNExternalDisplayEvent";
private static ExternalDisplayHelper instance = null;
private DisplayManager dm = null;
private Listener listener = null;
private Display displays = null;

// Private constructor to prevent direct instantiation
private ExternalDisplayHelper(Context context, Listener listener) {
this.listener = listener;
dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
if (dm != null) {
dm.registerDisplayListener(this, null);
} else {
}
}

// Method to initialize the singleton instance
public static synchronized void initialize(Context context, Listener listener) {
if (instance == null) {
instance = new ExternalDisplayHelper(context.getApplicationContext(), listener);
}
}

// Method to get the singleton instance
public static synchronized ExternalDisplayHelper getInstance() {
if (instance == null) {
throw new IllegalStateException("ExternalDisplayHelper is not initialized. Call initialize() first.");
}
return instance;
}

// Method to clean up the singleton instance
public static synchronized void destroy() {
if (instance != null && instance.dm != null) {
instance.dm.unregisterDisplayListener(instance);
instance = null;
}
}
public static Map<String, Object> getScreenInfo(Display[] displays) {
HashMap<String, Object> info = new HashMap<>();
for (Display display : displays) {
int displayId = display.getDisplayId();
if (
display.getDisplayId() == Display.DEFAULT_DISPLAY ||
(display.getFlags() & Display.FLAG_PRESENTATION) == 0
) {
continue;
}
HashMap<String, Object> data = new HashMap<>();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
data.put("id", displayId);
data.put("width", displayMetrics.widthPixels);
data.put("height", displayMetrics.heightPixels);
info.put(String.valueOf(display.getDisplayId()), data);
}
return info;
}

@Override
public void onDisplayAdded(int displayId) {
if (listener != null) {
listener.onDisplayAdded(getDisplays(), displayId);
}
}

@Override
public void onDisplayChanged(int displayId) {
if (listener != null) {
listener.onDisplayChanged(getDisplays(), displayId);
}
}

@Override
public void onDisplayRemoved(int displayId) {
if (listener != null) {
listener.onDisplayRemoved(getDisplays(), displayId);
}
}

public Display getDisplay(int displayId) {
if (dm != null) {
return dm.getDisplay(displayId);
}
return null;
}

public Display[] getDisplays() {
if (dm != null) {
return dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
}
return new Display[0];
}

public interface Listener {
void onDisplayAdded(Display[] displays, int displayId);
void onDisplayChanged(Display[] displays, int displayId);
void onDisplayRemoved(Display[] displays, int displayId);
}
return info;
}

public interface Listener {
void onDisplayAdded(Display[] displays, int displayId);
void onDisplayChanged(Display[] displays, int displayId);
void onDisplayRemoved(Display[] displays, int displayId);
}

private Listener listener = null;
private DisplayManager dm = null;
private Display displays = null;

public ExternalDisplayHelper(Context context, Listener listener) {
this.listener = listener;

dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
dm.registerDisplayListener(this, null);
}

public Display getDisplay(int displayId) {
return dm.getDisplay(displayId);
}

public Display[] getDisplays() {
return dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
}

@Override
public void onDisplayAdded(int displayId) {
listener.onDisplayAdded(getDisplays(), displayId);
}

@Override
public void onDisplayChanged(int displayId) {
listener.onDisplayChanged(getDisplays(), displayId);
}

@Override
public void onDisplayRemoved(int displayId) {
listener.onDisplayRemoved(getDisplays(), displayId);
}
}
Loading