Skip to content

Commit

Permalink
fix: mobile file upload menu (#6786)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin authored Nov 14, 2024
1 parent 651938a commit 7600961
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ class FileBlockComponentState extends State<FileBlockComponent>

RenderBox? get _renderBox => context.findRenderObject() as RenderBox?;

late EditorDropManagerState dropManagerState =
context.read<EditorDropManagerState>();
late EditorDropManagerState? dropManagerState = UniversalPlatform.isMobile
? null
: context.read<EditorDropManagerState>();

final fileKey = GlobalKey();
final showActionsNotifier = ValueNotifier<bool>(false);
Expand All @@ -176,7 +177,9 @@ class FileBlockComponentState extends State<FileBlockComponent>

@override
void didChangeDependencies() {
dropManagerState = context.read<EditorDropManagerState>();
if (!UniversalPlatform.isMobile) {
dropManagerState = context.read<EditorDropManagerState>();
}
super.didChangeDependencies();
}

Expand Down Expand Up @@ -240,17 +243,17 @@ class FileBlockComponentState extends State<FileBlockComponent>
if (url == null || url.isEmpty) {
child = DropTarget(
onDragEntered: (_) {
if (dropManagerState.isDropEnabled) {
if (dropManagerState?.isDropEnabled == true) {
setState(() => isDragging = true);
}
},
onDragExited: (_) {
if (dropManagerState.isDropEnabled) {
if (dropManagerState?.isDropEnabled == true) {
setState(() => isDragging = false);
}
},
onDragDone: (details) {
if (dropManagerState.isDropEnabled) {
if (dropManagerState?.isDropEnabled == true) {
insertFileFromLocal(details.files);
}
},
Expand All @@ -263,8 +266,8 @@ class FileBlockComponentState extends State<FileBlockComponent>
minHeight: 80,
),
clickHandler: PopoverClickHandler.gestureDetector,
onOpen: () => dropManagerState.add(FileBlockKeys.type),
onClose: () => dropManagerState.remove(FileBlockKeys.type),
onOpen: () => dropManagerState?.add(FileBlockKeys.type),
onClose: () => dropManagerState?.remove(FileBlockKeys.type),
popupBuilder: (_) => FileUploadMenu(
onInsertLocalFile: insertFileFromLocal,
onInsertNetworkFile: insertNetworkFile,
Expand Down Expand Up @@ -342,7 +345,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
void _openMenu() {
if (UniversalPlatform.isDesktopOrWeb) {
controller.show();
dropManagerState.add(FileBlockKeys.type);
dropManagerState?.add(FileBlockKeys.type);
} else {
showUploadFileMobileMenu();
}
Expand Down Expand Up @@ -502,7 +505,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
}

// Remove the file block from the drop state manager
dropManagerState.remove(FileBlockKeys.type);
dropManagerState?.remove(FileBlockKeys.type);

final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
Expand All @@ -524,7 +527,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
}

// Remove the file block from the drop state manager
dropManagerState.remove(FileBlockKeys.type);
dropManagerState?.remove(FileBlockKeys.type);

final uri = Uri.tryParse(url);
if (uri == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ class _FileUploadLocalState extends State<_FileUploadLocal> {

if (UniversalPlatform.isMobile) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
padding: const EdgeInsets.all(12),
child: SizedBox(
height: 32,
width: 300,
child: FlowyButton(
backgroundColor: Theme.of(context).colorScheme.primary,
hoverColor: Theme.of(context).colorScheme.primary.withOpacity(0.9),
Expand Down

0 comments on commit 7600961

Please sign in to comment.