Skip to content

Commit 53b642a

Browse files
authored
fix: context menu screen positioning (#5669)
1 parent 855fb0d commit 53b642a

File tree

16 files changed

+455
-213
lines changed

16 files changed

+455
-213
lines changed
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
using DCL.Helpers;
12
using DCLServices.CameraReelService;
23
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
4+
using UIComponents.ContextMenu;
55
using UnityEngine;
6-
using UnityEngine.EventSystems;
76
using UnityEngine.UI;
87

98
namespace DCLFeatures.CameraReel.Gallery
109
{
11-
public class ThumbnailContextMenuView : MonoBehaviour, IThumbnailContextMenuView
10+
[RequireComponent(typeof(RectTransform))]
11+
public class ThumbnailContextMenuView : ContextMenuComponentView, IThumbnailContextMenuView
1212
{
1313
public static readonly BaseList<ThumbnailContextMenuView> Instances = new ();
1414

@@ -24,23 +24,37 @@ public class ThumbnailContextMenuView : MonoBehaviour, IThumbnailContextMenuView
2424
public event Action OnShareToTwitterRequested;
2525
public event Action<CameraReelResponse> OnSetup;
2626

27-
private void Awake()
27+
public override void Awake()
2828
{
29+
base.Awake();
30+
31+
HidingHierarchyTransforms = new[]
32+
{
33+
transform,
34+
downloadButton.transform,
35+
deleteButton.transform,
36+
copyLinkButton.transform,
37+
shareToTwitterButton.transform,
38+
};
39+
2940
downloadButton.onClick.AddListener(() =>
3041
{
3142
OnDownloadRequested?.Invoke();
3243
Hide();
3344
});
45+
3446
deleteButton.onClick.AddListener(() =>
3547
{
3648
OnDeletePictureRequested?.Invoke();
3749
Hide();
3850
});
51+
3952
copyLinkButton.onClick.AddListener(() =>
4053
{
4154
OnCopyPictureLinkRequested?.Invoke();
4255
Hide();
4356
});
57+
4458
shareToTwitterButton.onClick.AddListener(() =>
4559
{
4660
OnShareToTwitterRequested?.Invoke();
@@ -55,43 +69,26 @@ private void OnDestroy()
5569
Instances.Remove(this);
5670
}
5771

58-
private void Update()
59-
{
60-
HideIfClickedOutside();
61-
}
72+
public override void RefreshControl() { }
6273

6374
public void Show(CameraReelResponse picture)
6475
{
6576
gameObject.SetActive(true);
77+
ClampPositionToScreenBorders(transform.position);
6678
OnSetup?.Invoke(picture);
6779
}
6880

69-
public void Dispose()
81+
public override void Hide(bool instant = false)
7082
{
71-
if (selfDestroy)
72-
Destroy(gameObject);
73-
}
83+
base.Hide(instant);
7484

75-
private void Hide() =>
7685
gameObject.SetActive(false);
86+
}
7787

78-
private void HideIfClickedOutside()
88+
public override void Dispose()
7989
{
80-
if (!Input.GetMouseButtonDown(0)) return;
81-
82-
var pointerEventData = new PointerEventData(EventSystem.current)
83-
{
84-
position = Input.mousePosition
85-
};
86-
87-
var raycastResults = new List<RaycastResult>();
88-
EventSystem.current.RaycastAll(pointerEventData, raycastResults);
89-
90-
if (raycastResults.All(result => result.gameObject != downloadButton.gameObject
91-
&& result.gameObject != deleteButton.gameObject
92-
&& result.gameObject != copyLinkButton.gameObject
93-
&& result.gameObject != shareToTwitterButton.gameObject))
94-
Hide();
90+
if (selfDestroy)
91+
Utils.SafeDestroy(gameObject);
9592
}
9693
}
9794
}

unity-renderer/Assets/DCLPlugins/CameraReelPlugin/CameraReelPlugin.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"GUID:1de3566cccb280f4a982c59ad0d08c96",
2121
"GUID:6426fc92c49cbb342916620a1009be8d",
2222
"GUID:fd6a19eb8dfe417a84a27e537222d98d",
23-
"GUID:c34e38f41494f834abff029ddf82af43"
23+
"GUID:c34e38f41494f834abff029ddf82af43",
24+
"GUID:81f3218b29e049144b175dad2ebbac1b"
2425
],
2526
"includePlatforms": [],
2627
"excludePlatforms": [],

unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/Tabs/FriendRequestsTabComponentView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ private void OnEntryCancelButtonPressed(FriendRequestEntry requestEntry)
354354

355355
private void OnEntryMenuToggle(FriendEntryBase friendEntry)
356356
{
357+
friendEntry.Dock(contextMenuPanel);
357358
contextMenuPanel.Show(friendEntry.Model.userId);
358359
contextMenuPanel.SetFriendshipContentActive(false);
359-
friendEntry.Dock(contextMenuPanel);
360360
}
361361

362362
private void UpdateCounterLabel()

unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/Tabs/FriendsTabComponentView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ private FriendEntry CreateEntry(string userId, Dictionary<string, PoolableObject
380380

381381
private void OnEntryMenuToggle(FriendEntryBase friendEntry)
382382
{
383-
contextMenuPanel.Show(friendEntry.Model.userId);
384383
friendEntry.Dock(contextMenuPanel);
384+
contextMenuPanel.Show(friendEntry.Model.userId);
385385
}
386386

387387
private Pool GetEntryPool()

unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Mentions/Mentions.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"GUID:f51ebe6a0ceec4240a699833d6309b23",
1010
"GUID:28f74c468a54948bfa9f625c5d428f56",
1111
"GUID:1e6b57fe78f7b724e9567f29f6a40c2c",
12-
"GUID:2995626b54c60644988f134a69a77450"
12+
"GUID:2995626b54c60644988f134a69a77450",
13+
"GUID:81f3218b29e049144b175dad2ebbac1b"
1314
],
1415
"includePlatforms": [],
1516
"excludePlatforms": [],

0 commit comments

Comments
 (0)