@@ -50,10 +50,6 @@ let googleImageName = "google"
5050/// The layout styles supported by the sign-in button.
5151///
5252/// The minimum size of the button depends on the language used for text.
53- /// The following dimensions (in points) fit for all languages:
54- /// - standard: 230 x 48
55- /// - wide: 312 x 48
56- /// - icon: 48 x 48 (no text, fixed size)
5753@available ( iOS 13 . 0 , macOS 10 . 15 , * )
5854public enum GoogleSignInButtonStyle {
5955 case standard
@@ -205,9 +201,13 @@ fileprivate struct Width {
205201extension GoogleSignInButtonStyle {
206202 fileprivate var width : Width {
207203 switch self {
208- case . icon: return Width ( min: iconWidth, max: iconWidth)
209- case . standard: return Width ( min: 90 , max: . infinity)
210- case . wide: return Width ( min: 170 , max: . infinity)
204+ case . icon:
205+ return Width ( min: iconWidth, max: iconWidth)
206+ case . standard, . wide:
207+ return Width (
208+ min: iconWidth + widthForButtonText + iconPadding + textPadding,
209+ max: . infinity
210+ )
211211 }
212212 }
213213
@@ -222,6 +222,28 @@ extension GoogleSignInButtonStyle {
222222 case . icon: return " "
223223 }
224224 }
225+
226+ var widthForButtonText : CGFloat {
227+ let bt = buttonText as NSString
228+ let size = CGSize ( width: . max, height: . max)
229+ let anyFont : Any
230+ #if os(iOS) || targetEnvironment(macCatalyst)
231+ anyFont = UIFont ( name: fontNameRobotoBold, size: fontSize) as Any
232+ #elseif os(macOS)
233+ anyFont = NSFont ( name: fontNameRobotoBold, size: fontSize) as Any
234+ #else
235+ fatalError ( " Unrecognized platform to calculate minimum width " )
236+ #endif
237+
238+ let rect = bt. boundingRect (
239+ with: size,
240+ options: [ ] ,
241+ attributes: [ . font: anyFont] ,
242+ context: nil
243+ )
244+
245+ return rect. width
246+ }
225247}
226248
227249// MARK: - Button Style
0 commit comments