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
15 changes: 8 additions & 7 deletions ios/RNMagicScript/components/Utils/Dialog/DialogPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ class DialogPresenter: DialogPresenting {
}

fileprivate func addBackgroudView() {
backgroundView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.width, height: UIScreen.height))
backgroundView = UIView()
backgroundView.translatesAutoresizingMaskIntoConstraints = false
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.35)
parentView.addSubview(backgroundView)
NSLayoutConstraint.activate([
backgroundView.leftAnchor.constraint(lessThanOrEqualTo: parentView.leftAnchor),
backgroundView.rightAnchor.constraint(lessThanOrEqualTo: parentView.rightAnchor),
backgroundView.topAnchor.constraint(lessThanOrEqualTo: parentView.topAnchor),
backgroundView.bottomAnchor.constraint(lessThanOrEqualTo: parentView.bottomAnchor)
backgroundView.leftAnchor.constraint(equalTo: parentView.leftAnchor, constant: 0.0),
backgroundView.rightAnchor.constraint(equalTo: parentView.rightAnchor, constant: 0.0),
backgroundView.topAnchor.constraint(equalTo: parentView.topAnchor, constant: 0.0),
backgroundView.bottomAnchor.constraint(equalTo: parentView.bottomAnchor, constant: 0.0)
])
}

Expand All @@ -54,8 +55,8 @@ class DialogPresenter: DialogPresenting {
NSLayoutConstraint.activate([
dialogView.widthAnchor.constraint(equalToConstant: DialogView.width),
dialogView.heightAnchor.constraint(lessThanOrEqualToConstant: min(dialogView.frame.height, DialogView.height)),
dialogView.centerXAnchor.constraint(lessThanOrEqualTo: backgroundView.centerXAnchor),
dialogView.centerYAnchor.constraint(lessThanOrEqualTo: backgroundView.centerYAnchor)
dialogView.centerXAnchor.constraint(equalTo: backgroundView.centerXAnchor),
dialogView.centerYAnchor.constraint(equalTo: backgroundView.centerYAnchor)
])
presentedDialogs[dialog.id] = dialogView
}
Expand Down
28 changes: 17 additions & 11 deletions ios/RNMagicScript/components/Utils/Dialog/DialogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class DialogView: UIView {
}

static var height: CGFloat {
return DialogView.width * 0.75
let margin: CGFloat = 16.0
return max(UIScreen.height, UIScreen.width) - 2 * margin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't the height here be a lot bigger now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will, but it does not matter. The height will be reduced by auto-layout. For some reason, it's easier for auto-layout to shrink the view rather than to expand it. I tested it on small and bigger screens (both portrait and landscape) and works fine.

}

var dialogData: DialogDataProviding? {
Expand Down Expand Up @@ -113,21 +114,21 @@ class DialogView: UIView {
target: self,
action: #selector(cancelButtonAction(_:)))

let buttonsContainer = UIView()
buttonsContainer.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer.addSubview(cancelButton)
buttonsContainer.addSubview(confirmButton)

let margin: CGFloat = 16.0

let buttonsContainer: UIStackView = UIStackView()
buttonsContainer.axis = .horizontal
buttonsContainer.alignment = .center
buttonsContainer.spacing = margin
buttonsContainer.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer.addArrangedSubview(cancelButton)
buttonsContainer.addArrangedSubview(confirmButton)

NSLayoutConstraint.activate([
cancelButton.topAnchor.constraint(equalTo: buttonsContainer.topAnchor, constant: 0),
cancelButton.bottomAnchor.constraint(equalTo: buttonsContainer.bottomAnchor, constant: 0),
cancelButton.leftAnchor.constraint(equalTo: buttonsContainer.leftAnchor, constant: margin),
cancelButton.rightAnchor.constraint(equalTo: confirmButton.leftAnchor, constant: -margin),
confirmButton.topAnchor.constraint(equalTo: buttonsContainer.topAnchor, constant: 0),
confirmButton.bottomAnchor.constraint(equalTo: buttonsContainer.bottomAnchor, constant: 0),
confirmButton.rightAnchor.constraint(equalTo: buttonsContainer.rightAnchor, constant: -margin),
])

addSubview(buttonsContainer)
Expand All @@ -144,6 +145,11 @@ class DialogView: UIView {
buttonsContainer.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -margin),
buttonsContainer.centerXAnchor.constraint(equalTo: centerXAnchor)
])

// if vertical content is too big, make sure the action buttons are compacted
messageTextView.setContentHuggingPriority(.defaultLow, for: .vertical)
cancelButton.setContentHuggingPriority(.defaultHigh, for: .vertical)
confirmButton.setContentHuggingPriority(.defaultHigh, for: .vertical)

setExpirationTimer()
}
Expand Down Expand Up @@ -177,9 +183,9 @@ class DialogView: UIView {

switch dialogData?.buttonType {
case .textWithIcon:
confirmButton.contentEdgeInsets = UIEdgeInsets(top: 4.0, left: 16.0, bottom: 4.0, right: 24.0)
confirmButton.contentEdgeInsets = UIEdgeInsets(top: 8.0, left: 16.0, bottom: 8.0, right: 24.0)
confirmButton.titleEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: -8.0)
cancelButton.contentEdgeInsets = UIEdgeInsets(top: 4.0, left: 16.0, bottom: 4.0, right: 24.0)
cancelButton.contentEdgeInsets = UIEdgeInsets(top: 8.0, left: 16.0, bottom: 8.0, right: 24.0)
cancelButton.titleEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: -8.0)
confirmButton.layer.cornerRadius = confirmButton.bounds.height / 2
confirmButton.layer.borderWidth = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//

import UIKit

Expand All @@ -34,7 +34,7 @@ extension UIButton {

func update(image: UIImage?) {
if let buttonImage = image {
self.setImage(UIImage.image(with: buttonImage, scaledToSize: CGSize(width: 28.0, height: 28.0)), for: UIControl.State.normal)
self.setImage(UIImage.image(with: buttonImage, scaledToSize: CGSize(width: 18.0, height: 18.0)), for: UIControl.State.normal)
self.imageView?.contentMode = .scaleAspectFit
self.setNeedsLayout()
}
Expand Down
15 changes: 12 additions & 3 deletions ios/RNMagicScriptHostApplication/sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class ViewController: UIViewController {

// setupPrismWithModels()
// setupPrismForHitTest()
// setupPrismForDialog()
setupPrismForFontTest()
setupPrismForDialog()
// setupPrismForFontTest()

setupARView()
arView.register(self)
Expand Down Expand Up @@ -89,7 +89,16 @@ class ViewController: UIViewController {
"text": "Dialog"
], nodeId: "button_dialog", parentId: prismId)

dialogNode = UiDialogNode(props: ["buttonType": "text-with-icon", "title": "Dialog title", "message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "confirmText": "Confirm", "confirmIcon": "check", "cancelText": "Confirm", "cancelIcon": "close", "scrolling": true ])
dialogNode = UiDialogNode(props: [
"buttonType": "text-with-icon",
"title": "Dialog title",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"confirmText": "Confirm",
"confirmIcon": "check",
"cancelText": "Cancel",
"cancelIcon": "close",
"scrolling": true
])
dialogNode?.onDialogConfirmed = { [weak self] dialog in
if let dialogId = self?.dialogNodeId { NodesManager.instance.removeNode(dialogId, fromParent: prismId) }
}
Expand Down